Revision 30 org.gvsig.expressionfield/trunk/org.gvsig.expressionfield/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Perimeter.java
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 |
} |
Also available in: Unified diff