Revision 30
org.gvsig.expressionfield/trunk/org.gvsig.expressionfield/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Perimeter.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
1 |
/** |
|
2 |
* ***************************************************************************** |
|
2 | 3 |
* |
3 |
* gvSIG. Desktop Geographic Information System.
|
|
4 |
*
|
|
5 |
* Copyright (C) 2007-2013 gvSIG Association.
|
|
6 |
*
|
|
7 |
* This program is free software; you can redistribute it and/or
|
|
8 |
* modify it under the terms of the GNU General Public License
|
|
9 |
* as published by the Free Software Foundation; either version 3
|
|
10 |
* of the License, or (at your option) any later version.
|
|
11 |
*
|
|
12 |
* This program is distributed in the hope that it will be useful,
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
* GNU General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License
|
|
18 |
* along with this program; if not, write to the Free Software
|
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
20 |
* MA 02110-1301, USA.
|
|
21 |
*
|
|
22 |
* For any additional information, do not hesitate to contact us
|
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
24 |
*
|
|
25 |
*******************************************************************************/
|
|
4 |
* gvSIG. Desktop Geographic Information System. |
|
5 |
* |
|
6 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or modify it under
|
|
9 |
* the terms of the GNU General Public License as published by the Free Software
|
|
10 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
11 |
* version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
16 |
* details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License along with
|
|
19 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
20 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us at info AT
|
|
23 |
* gvsig.com, or visit our website www.gvsig.com.
|
|
24 |
* |
|
25 |
******************************************************************************
|
|
26 |
*/ |
|
26 | 27 |
package org.gvsig.expressionfield.project.documents.table.operators; |
27 | 28 |
|
28 | 29 |
import java.awt.geom.Point2D; |
... | ... | |
44 | 45 |
/** |
45 | 46 |
* @author Vicente Caballero Navarro |
46 | 47 |
*/ |
47 |
public class Perimeter extends GraphicOperator{ |
|
48 |
public class Perimeter extends GraphicOperator {
|
|
48 | 49 |
|
49 |
public String addText(String s) { |
|
50 |
return s.concat(toString()+"()"); |
|
51 |
} |
|
52 |
public double process(Feature feature) { |
|
50 |
public String addText(String s) { |
|
51 |
return s.concat(toString() + "()"); |
|
52 |
} |
|
53 |
|
|
54 |
public double process(Feature feature) { |
|
53 | 55 |
// ReadableVectorial adapter = getLayer().getSource(); |
54 |
org.gvsig.fmap.geom.Geometry geom=null;
|
|
55 |
geom = feature.getDefaultGeometry();//adapter.getShape(index.get());
|
|
56 |
ArrayList parts=getXY(geom);
|
|
57 |
double perimeter=0;
|
|
58 |
for (int j=0;j<parts.size();j++){
|
|
59 |
Double[][] xsys=(Double[][])parts.get(j);//getXY(geom);
|
|
60 |
double dist = 0;
|
|
61 |
double distAll = 0; |
|
56 |
org.gvsig.fmap.geom.Geometry geom = null;
|
|
57 |
geom = feature.getDefaultGeometry();//adapter.getShape(index.get());
|
|
58 |
ArrayList parts = getXY(geom);
|
|
59 |
double perimeter = 0;
|
|
60 |
for (int j = 0; j < parts.size(); j++) {
|
|
61 |
Double[][] xsys = (Double[][]) parts.get(j);//getXY(geom);
|
|
62 |
double dist = 0;
|
|
63 |
double distAll = 0;
|
|
62 | 64 |
|
63 |
ViewPort vp = getLayer().getMapContext().getViewPort(); |
|
64 |
for (int i = 0; i < (xsys[0].length - 1); i++) { |
|
65 |
dist = 0; |
|
65 |
ViewPort vp = getLayer().getMapContext().getViewPort();
|
|
66 |
for (int i = 0; i < (xsys[0].length - 1); i++) {
|
|
67 |
dist = 0;
|
|
66 | 68 |
|
67 |
Point2D p = new Point2D.Double(xsys[0][i].doubleValue(), xsys[1][i].doubleValue());//vp.toMapPoint(new Point(event.getXs()[i].intValue(), event.getYs()[i].intValue())); |
|
68 |
Point2D p2 = new Point2D.Double(xsys[0][i + 1].doubleValue(), xsys[1][i + 1].doubleValue());//vp.toMapPoint(new Point(event.getXs()[i + 1].intValue(), event.getYs()[i + 1].intValue())); |
|
69 |
dist = vp.distanceWorld(p,p2); |
|
70 |
//System.out.println("distancia parcial = "+dist); |
|
71 |
distAll += dist; |
|
69 |
Point2D p = new Point2D.Double(xsys[0][i].doubleValue(), xsys[1][i].doubleValue());//vp.toMapPoint(new Point(event.getXs()[i].intValue(), event.getYs()[i].intValue())); |
|
70 |
Point2D p2 = new Point2D.Double(xsys[0][i + 1].doubleValue(), xsys[1][i + 1].doubleValue());//vp.toMapPoint(new Point(event.getXs()[i + 1].intValue(), event.getYs()[i + 1].intValue())); |
|
71 |
dist = vp.distanceWorld(p, p2); |
|
72 |
//System.out.println("distancia parcial = "+dist); |
|
73 |
distAll += dist; |
|
74 |
} |
|
75 |
int distanceUnits = vp.getDistanceUnits(); |
|
76 |
perimeter += distAll / MapContext.getDistanceTrans2Meter()[distanceUnits]; |
|
72 | 77 |
} |
73 |
int distanceUnits=vp.getDistanceUnits(); |
|
74 |
perimeter+= distAll/MapContext.getDistanceTrans2Meter()[distanceUnits]; |
|
75 |
} |
|
76 |
return perimeter; |
|
77 |
} |
|
78 |
public void eval(BSFManager interpreter) throws BSFException { |
|
79 |
interpreter.declareBean("jperimeter",this,Perimeter.class); |
|
78 |
return perimeter; |
|
79 |
} |
|
80 |
|
|
81 |
public void eval(BSFManager interpreter) throws BSFException { |
|
82 |
interpreter.declareBean("jperimeter", this, Perimeter.class); |
|
80 | 83 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double perimeter(){return jperimeter.process(indexRow);};"); |
81 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def perimeter():\n" + |
|
82 |
" return jperimeter.process(featureContainer.getFeature())"); |
|
83 |
} |
|
84 |
public String toString() { |
|
85 |
return "perimeter"; |
|
86 |
} |
|
87 |
public boolean isEnable() { |
|
88 |
if (getLayer()==null) |
|
89 |
return false; |
|
90 |
int geomType=org.gvsig.fmap.geom.Geometry.TYPES.POINT; |
|
91 |
try { |
|
92 |
FeatureStore store = getLayer().getFeatureStore(); |
|
93 |
geomType = store.getDefaultFeatureType().getAttributeDescriptor(store.getDefaultFeatureType().getDefaultGeometryAttributeIndex()).getGeometryType(); |
|
94 |
} catch (DataException e) { |
|
95 |
NotificationManager.addError(e); |
|
96 |
} |
|
97 |
return (getType()==IOperator.NUMBER && |
|
98 |
(geomType==org.gvsig.fmap.geom.Geometry.TYPES.SURFACE |
|
99 |
|| geomType==org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE |
|
100 |
|| geomType==org.gvsig.fmap.geom.Geometry.TYPES.CURVE |
|
101 |
|| geomType==org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE |
|
102 |
)); |
|
103 |
} |
|
104 |
public String getTooltip(){ |
|
105 |
return PluginServices.getText(this,"operator")+": "+addText("")+"\n"+getDescription(); |
|
106 |
} |
|
107 |
public String getDescription() { |
|
108 |
return PluginServices.getText(this, "returns") + ": " + |
|
109 |
PluginServices.getText(this, "numeric_value") + "\n" + |
|
110 |
PluginServices.getText(this, "description") + ": " + |
|
111 |
"Returns the perimeter of polygon or line geometry of this row."; |
|
84 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def perimeter():\n" |
|
85 |
+ " return jperimeter.process(featureContainer.getFeature())"); |
|
112 | 86 |
} |
87 |
|
|
88 |
public String toString() { |
|
89 |
return "perimeter"; |
|
90 |
} |
|
91 |
|
|
92 |
public boolean isEnable() { |
|
93 |
if (getLayer() == null) { |
|
94 |
return false; |
|
95 |
} |
|
96 |
int geomType = org.gvsig.fmap.geom.Geometry.TYPES.POINT; |
|
97 |
try { |
|
98 |
FeatureStore store = getLayer().getFeatureStore(); |
|
99 |
geomType = store.getDefaultFeatureType().getAttributeDescriptor(store.getDefaultFeatureType().getDefaultGeometryAttributeIndex()).getGeometryType(); |
|
100 |
} catch (DataException e) { |
|
101 |
NotificationManager.addError(e); |
|
102 |
} |
|
103 |
return (getType() == IOperator.NUMBER |
|
104 |
&& (geomType == org.gvsig.fmap.geom.Geometry.TYPES.SURFACE |
|
105 |
|| geomType == org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE |
|
106 |
|| geomType == org.gvsig.fmap.geom.Geometry.TYPES.CURVE |
|
107 |
|| geomType == org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE)); |
|
108 |
} |
|
109 |
|
|
110 |
public String getTooltip() { |
|
111 |
return PluginServices.getText(this, "operator") + ": " + addText("") + "\n" + getDescription(); |
|
112 |
} |
|
113 |
|
|
114 |
public String getDescription() { |
|
115 |
return PluginServices.getText(this, "returns") + ": " |
|
116 |
+ PluginServices.getText(this, "numeric_value") + "\n" |
|
117 |
+ PluginServices.getText(this, "description") + ": " |
|
118 |
+ "Returns the perimeter of polygon or line geometry of this row in the units of the view."; |
|
119 |
} |
|
113 | 120 |
} |
org.gvsig.expressionfield/trunk/org.gvsig.expressionfield/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Area.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
1 |
/** |
|
2 |
* ***************************************************************************** |
|
2 | 3 |
* |
3 |
* gvSIG. Desktop Geographic Information System.
|
|
4 |
*
|
|
5 |
* Copyright (C) 2007-2013 gvSIG Association.
|
|
6 |
*
|
|
7 |
* This program is free software; you can redistribute it and/or
|
|
8 |
* modify it under the terms of the GNU General Public License
|
|
9 |
* as published by the Free Software Foundation; either version 3
|
|
10 |
* of the License, or (at your option) any later version.
|
|
11 |
*
|
|
12 |
* This program is distributed in the hope that it will be useful,
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
* GNU General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License
|
|
18 |
* along with this program; if not, write to the Free Software
|
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
20 |
* MA 02110-1301, USA.
|
|
21 |
*
|
|
22 |
* For any additional information, do not hesitate to contact us
|
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
24 |
*
|
|
25 |
*******************************************************************************/
|
|
4 |
* gvSIG. Desktop Geographic Information System. |
|
5 |
* |
|
6 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or modify it under
|
|
9 |
* the terms of the GNU General Public License as published by the Free Software
|
|
10 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
11 |
* version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
16 |
* details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License along with
|
|
19 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
20 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us at info AT
|
|
23 |
* gvsig.com, or visit our website www.gvsig.com.
|
|
24 |
* |
|
25 |
******************************************************************************
|
|
26 |
*/ |
|
26 | 27 |
package org.gvsig.expressionfield.project.documents.table.operators; |
27 | 28 |
|
28 | 29 |
import java.awt.geom.Point2D; |
... | ... | |
43 | 44 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
44 | 45 |
import com.vividsolutions.jts.geom.Coordinate; |
45 | 46 |
import com.vividsolutions.jts.geom.CoordinateList; |
47 |
|
|
46 | 48 |
/** |
47 | 49 |
* @author Vicente Caballero Navarro |
48 | 50 |
*/ |
49 |
public class Area extends GraphicOperator{ |
|
51 |
public class Area extends GraphicOperator {
|
|
50 | 52 |
|
51 |
public String addText(String s) { |
|
52 |
return s.concat(toString()+"()"); |
|
53 |
} |
|
54 |
public double process(org.gvsig.fmap.dal.feature.Feature feature){ |
|
53 |
public String addText(String s) { |
|
54 |
return s.concat(toString() + "()"); |
|
55 |
} |
|
56 |
|
|
57 |
public double process(org.gvsig.fmap.dal.feature.Feature feature) { |
|
55 | 58 |
// ReadableVectorial adapter = getLayer().getSource(); |
56 |
org.gvsig.fmap.geom.Geometry geom=null;
|
|
59 |
org.gvsig.fmap.geom.Geometry geom = null;
|
|
57 | 60 |
// try { |
58 |
geom = feature.getDefaultGeometry();//adapter.getShape(index.get());
|
|
61 |
geom = feature.getDefaultGeometry();//adapter.getShape(index.get());
|
|
59 | 62 |
// } catch (ExpansionFileReadException e) { |
60 | 63 |
// throw new DriverIOException(e); |
61 | 64 |
// } catch (ReadDriverException e) { |
62 | 65 |
// throw new DriverIOException(e); |
63 | 66 |
// } |
64 | 67 |
// int distanceUnits=getLayer().getMapContext().getViewPort().getDistanceArea(); |
65 |
return returnArea(geom);///Math.pow(MapContext.getAreaTrans2Meter()[distanceUnits],2); |
|
66 |
} |
|
67 |
public void eval(BSFManager interpreter) throws BSFException { |
|
68 |
interpreter.declareBean("jarea",this,Area.class); |
|
68 |
return returnArea(geom);///Math.pow(MapContext.getAreaTrans2Meter()[distanceUnits],2); |
|
69 |
} |
|
70 |
|
|
71 |
public void eval(BSFManager interpreter) throws BSFException { |
|
72 |
interpreter.declareBean("jarea", this, Area.class); |
|
69 | 73 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double area(){return area.process(indexRow);};"); |
70 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def area():\n" + |
|
71 |
" return jarea.process(featureContainer.getFeature())"); |
|
72 |
} |
|
73 |
public String toString() { |
|
74 |
return "area"; |
|
75 |
} |
|
76 |
public boolean isEnable() { |
|
77 |
if (getLayer()==null) |
|
78 |
return false; |
|
79 |
FeatureStore store; |
|
80 |
int geomType=Geometry.TYPES.POINT; |
|
81 |
try { |
|
82 |
store = getLayer().getFeatureStore(); |
|
83 |
geomType = store.getDefaultFeatureType().getAttributeDescriptor(store.getDefaultFeatureType().getDefaultGeometryAttributeIndex()).getGeometryType(); |
|
84 |
} catch (DataException e) { |
|
85 |
NotificationManager.addError(e); |
|
86 |
} |
|
87 |
return (getType()==IOperator.NUMBER && |
|
88 |
|
|
89 |
(geomType==Geometry.TYPES.SURFACE |
|
90 |
|| geomType==Geometry.TYPES.MULTISURFACE) |
|
91 |
|
|
92 |
); |
|
93 |
} |
|
74 |
interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def area():\n" |
|
75 |
+ " return jarea.process(featureContainer.getFeature())"); |
|
76 |
} |
|
94 | 77 |
|
95 |
private double returnArea(org.gvsig.fmap.geom.Geometry geom) { |
|
96 |
ArrayList parts=getXY(geom); |
|
97 |
double area=0; |
|
98 |
for (int i=0;i<parts.size();i++){ |
|
99 |
Double[][] xsys=(Double[][])parts.get(i);//getXY(geom); |
|
100 |
Double[] xs=xsys[0]; |
|
101 |
Double[] ys=xsys[1]; |
|
102 |
IProjection proj=getLayer().getMapContext().getProjection(); |
|
103 |
if (isCCW(xs, ys)){ |
|
104 |
if (proj.isProjected()) { |
|
105 |
area-= returnCoordsArea(xs,ys,new Point2D.Double(xs[xs.length-1].doubleValue(),ys[ys.length-1].doubleValue())); |
|
106 |
}else{ |
|
107 |
area-= returnGeoCArea(xs,ys); |
|
108 |
} |
|
109 |
}else{ |
|
110 |
if (proj.isProjected()) { |
|
111 |
area+= returnCoordsArea(xs,ys,new Point2D.Double(xs[xs.length-1].doubleValue(),ys[ys.length-1].doubleValue())); |
|
112 |
}else{ |
|
113 |
area+= returnGeoCArea(xs,ys); |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
return area; |
|
118 |
} |
|
78 |
public String toString() { |
|
79 |
return "area"; |
|
80 |
} |
|
119 | 81 |
|
120 |
public boolean isCCW(Double[] xs, Double[] ys){ |
|
121 |
CoordinateList coordList = new CoordinateList(); |
|
122 |
for (int i = 0; i < ys.length; i++) { |
|
123 |
Coordinate coord=new Coordinate(xs[i].doubleValue(),ys[i].doubleValue()); |
|
124 |
coordList.add(coord); |
|
125 |
} |
|
126 |
if (coordList.isEmpty()) |
|
127 |
return true; |
|
128 |
return CGAlgorithms.isCCW(coordList.toCoordinateArray()); |
|
129 |
} |
|
82 |
public boolean isEnable() { |
|
83 |
if (getLayer() == null) { |
|
84 |
return false; |
|
85 |
} |
|
86 |
FeatureStore store; |
|
87 |
int geomType = Geometry.TYPES.POINT; |
|
88 |
try { |
|
89 |
store = getLayer().getFeatureStore(); |
|
90 |
geomType = store.getDefaultFeatureType().getAttributeDescriptor(store.getDefaultFeatureType().getDefaultGeometryAttributeIndex()).getGeometryType(); |
|
91 |
} catch (DataException e) { |
|
92 |
NotificationManager.addError(e); |
|
93 |
} |
|
94 |
return (getType() == IOperator.NUMBER |
|
95 |
&& (geomType == Geometry.TYPES.SURFACE |
|
96 |
|| geomType == Geometry.TYPES.MULTISURFACE)); |
|
97 |
} |
|
130 | 98 |
|
99 |
private double returnArea(org.gvsig.fmap.geom.Geometry geom) { |
|
100 |
ArrayList parts = getXY(geom); |
|
101 |
double area = 0; |
|
102 |
for (int i = 0; i < parts.size(); i++) { |
|
103 |
Double[][] xsys = (Double[][]) parts.get(i);//getXY(geom); |
|
104 |
Double[] xs = xsys[0]; |
|
105 |
Double[] ys = xsys[1]; |
|
106 |
IProjection proj = getLayer().getMapContext().getProjection(); |
|
107 |
if (isCCW(xs, ys)) { |
|
108 |
if (proj.isProjected()) { |
|
109 |
area -= returnCoordsArea(xs, ys, new Point2D.Double(xs[xs.length - 1].doubleValue(), ys[ys.length - 1].doubleValue())); |
|
110 |
} else { |
|
111 |
area -= returnGeoCArea(xs, ys); |
|
112 |
} |
|
113 |
} else { |
|
114 |
if (proj.isProjected()) { |
|
115 |
area += returnCoordsArea(xs, ys, new Point2D.Double(xs[xs.length - 1].doubleValue(), ys[ys.length - 1].doubleValue())); |
|
116 |
} else { |
|
117 |
area += returnGeoCArea(xs, ys); |
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
return area; |
|
122 |
} |
|
131 | 123 |
|
132 |
private double returnGeoCArea(Double[] xs,Double[] ys) { |
|
133 |
double[] lat=new double[xs.length]; |
|
134 |
double[] lon=new double[xs.length]; |
|
135 |
for (int K= 0; K < xs.length; K++){ |
|
136 |
lon[K]= xs[K].doubleValue()/org.gvsig.fmap.mapcontrol.tools.geo.Geo.Degree; |
|
137 |
lat[K]= ys[K].doubleValue()/org.gvsig.fmap.mapcontrol.tools.geo.Geo.Degree; |
|
138 |
} |
|
139 |
return (org.gvsig.fmap.mapcontrol.tools.geo.Geo.sphericalPolyArea(lat,lon,xs.length-1)*org.gvsig.fmap.mapcontrol.tools.geo.Geo.SqM); |
|
140 |
} |
|
141 |
/** |
|
142 |
* Calcula el ?rea. |
|
143 |
* |
|
144 |
* @param aux ?ltimo punto. |
|
145 |
* |
|
146 |
* @return ?rea. |
|
147 |
*/ |
|
148 |
public double returnCoordsArea(Double[] xs,Double[] ys, Point2D point) { |
|
149 |
Point2D aux=point; |
|
150 |
double elArea = 0.0; |
|
151 |
Point2D pPixel; |
|
152 |
Point2D p = new Point2D.Double(); |
|
153 |
Point2D.Double pAnt = new Point2D.Double(); |
|
154 |
org.gvsig.fmap.mapcontext.ViewPort vp = getLayer().getMapContext().getViewPort(); |
|
155 |
for (int pos = 0; pos < xs.length-1; pos++) { |
|
156 |
pPixel = new Point2D.Double(xs[pos].doubleValue(), |
|
157 |
ys[pos].doubleValue()); |
|
158 |
p = pPixel; |
|
159 |
if (pos == 0) { |
|
160 |
pAnt.x = aux.getX(); |
|
161 |
pAnt.y = aux.getY(); |
|
162 |
} |
|
163 |
elArea = elArea + ((pAnt.x - p.getX()) * (pAnt.y + p.getY())); |
|
164 |
pAnt.setLocation(p); |
|
165 |
} |
|
124 |
public boolean isCCW(Double[] xs, Double[] ys) { |
|
125 |
CoordinateList coordList = new CoordinateList(); |
|
126 |
for (int i = 0; i < ys.length; i++) { |
|
127 |
Coordinate coord = new Coordinate(xs[i].doubleValue(), ys[i].doubleValue()); |
|
128 |
coordList.add(coord); |
|
129 |
} |
|
130 |
if (coordList.isEmpty()) { |
|
131 |
return true; |
|
132 |
} |
|
133 |
return CGAlgorithms.isCCW(coordList.toCoordinateArray()); |
|
134 |
} |
|
166 | 135 |
|
167 |
elArea = elArea + ((pAnt.x - aux.getX()) * (pAnt.y + aux.getY())); |
|
168 |
elArea = Math.abs(elArea / 2.0); |
|
169 |
return (elArea/(Math.pow(org.gvsig.fmap.mapcontext.MapContext.getAreaTrans2Meter()[vp.getDistanceArea()],2))); |
|
170 |
} |
|
171 |
public String getTooltip(){ |
|
172 |
return PluginServices.getText(this,"operator")+": "+addText("")+"\n"+getDescription(); |
|
173 |
} |
|
174 |
public String getDescription() { |
|
175 |
return PluginServices.getText(this, "returns") + ": " + |
|
176 |
PluginServices.getText(this, "numeric_value") + "\n" + |
|
177 |
PluginServices.getText(this, "description") + ": " + |
|
178 |
"Returns the area of polygon geometry of this row."; |
|
136 |
private double returnGeoCArea(Double[] xs, Double[] ys) { |
|
137 |
double[] lat = new double[xs.length]; |
|
138 |
double[] lon = new double[xs.length]; |
|
139 |
for (int K = 0; K < xs.length; K++) { |
|
140 |
lon[K] = xs[K].doubleValue() / org.gvsig.fmap.mapcontrol.tools.geo.Geo.Degree; |
|
141 |
lat[K] = ys[K].doubleValue() / org.gvsig.fmap.mapcontrol.tools.geo.Geo.Degree; |
|
142 |
} |
|
143 |
return (org.gvsig.fmap.mapcontrol.tools.geo.Geo.sphericalPolyArea(lat, lon, xs.length - 1) * org.gvsig.fmap.mapcontrol.tools.geo.Geo.SqM); |
|
179 | 144 |
} |
145 |
|
|
146 |
/** |
|
147 |
* Calcula el ?rea. |
|
148 |
* |
|
149 |
* @param aux ?ltimo punto. |
|
150 |
* |
|
151 |
* @return ?rea. |
|
152 |
*/ |
|
153 |
public double returnCoordsArea(Double[] xs, Double[] ys, Point2D point) { |
|
154 |
Point2D aux = point; |
|
155 |
double elArea = 0.0; |
|
156 |
Point2D pPixel; |
|
157 |
Point2D p = new Point2D.Double(); |
|
158 |
Point2D.Double pAnt = new Point2D.Double(); |
|
159 |
org.gvsig.fmap.mapcontext.ViewPort vp = getLayer().getMapContext().getViewPort(); |
|
160 |
for (int pos = 0; pos < xs.length - 1; pos++) { |
|
161 |
pPixel = new Point2D.Double(xs[pos].doubleValue(), |
|
162 |
ys[pos].doubleValue()); |
|
163 |
p = pPixel; |
|
164 |
if (pos == 0) { |
|
165 |
pAnt.x = aux.getX(); |
|
166 |
pAnt.y = aux.getY(); |
|
167 |
} |
|
168 |
elArea = elArea + ((pAnt.x - p.getX()) * (pAnt.y + p.getY())); |
|
169 |
pAnt.setLocation(p); |
|
170 |
} |
|
171 |
|
|
172 |
elArea = elArea + ((pAnt.x - aux.getX()) * (pAnt.y + aux.getY())); |
|
173 |
elArea = Math.abs(elArea / 2.0); |
|
174 |
return (elArea / (Math.pow(org.gvsig.fmap.mapcontext.MapContext.getAreaTrans2Meter()[vp.getDistanceArea()], 2))); |
|
175 |
} |
|
176 |
|
|
177 |
public String getTooltip() { |
|
178 |
return PluginServices.getText(this, "operator") + ": " + addText("") + "\n" + getDescription(); |
|
179 |
} |
|
180 |
|
|
181 |
public String getDescription() { |
|
182 |
return PluginServices.getText(this, "returns") + ": " |
|
183 |
+ PluginServices.getText(this, "numeric_value") + "\n" |
|
184 |
+ PluginServices.getText(this, "description") + ": " |
|
185 |
+ "Returns the area of polygon geometry of this row in the units of the view."; |
|
186 |
} |
|
180 | 187 |
} |
org.gvsig.expressionfield/trunk/org.gvsig.expressionfield/pom.xml | ||
---|---|---|
9 | 9 |
|
10 | 10 |
<parent> |
11 | 11 |
<groupId>org.gvsig</groupId> |
12 |
<artifactId>org.gvsig.desktop.plugin</artifactId>
|
|
13 |
<version>2.0.21</version>
|
|
12 |
<artifactId>org.gvsig.desktop</artifactId> |
|
13 |
<version>2.0.49</version>
|
|
14 | 14 |
</parent> |
15 | 15 |
|
16 | 16 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-expression-field</url> |
17 | 17 |
Also available in: Unified diff