root / trunk / libraries / libExpressions / src / main / java / org / gvsig / operators / PointX.java @ 23299
History | View | Annotate | Download (2.38 KB)
1 |
package org.gvsig.operators; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.apache.bsf.BSFException; |
6 |
import org.apache.bsf.BSFManager; |
7 |
import org.gvsig.baseclasses.GraphicOperator; |
8 |
import org.gvsig.baseclasses.IOperator; |
9 |
import org.gvsig.baseclasses.Index; |
10 |
import org.gvsig.expresions.EvalOperatorsTask; |
11 |
|
12 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
13 |
import com.iver.andami.messages.NotificationManager; |
14 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
15 |
import com.iver.cit.gvsig.fmap.core.FShape; |
16 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
17 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
18 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
19 |
/**
|
20 |
* @author Vicente Caballero Navarro
|
21 |
*/
|
22 |
public class PointX extends GraphicOperator{ |
23 |
|
24 |
public String addText(String s) { |
25 |
return s.concat(toString()+"()"); |
26 |
} |
27 |
public double process(Index index) throws DriverIOException { |
28 |
ReadableVectorial adapter = getLayer().getSource(); |
29 |
IGeometry geom=null;
|
30 |
try {
|
31 |
geom = adapter.getShape(index.get()); |
32 |
} catch (ExpansionFileReadException e) {
|
33 |
throw new DriverIOException(e); |
34 |
} catch (ReadDriverException e) {
|
35 |
throw new DriverIOException(e); |
36 |
} |
37 |
ArrayList parts=getXY(geom);
|
38 |
Double[][] xsys=(Double[][])parts.get(0);//getXY(geom); |
39 |
return xsys[0][0].doubleValue(); |
40 |
} |
41 |
public void eval(BSFManager interpreter) throws BSFException { |
42 |
interpreter.declareBean("pointX",this,PointX.class); |
43 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double x(){return pointX.process(indexRow);};");
|
44 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"def x():\n" + |
45 |
" return pointX.process(indexRow)");
|
46 |
} |
47 |
public String toString() { |
48 |
return "x"; |
49 |
} |
50 |
public boolean isEnable() { |
51 |
if (getLayer()==null) |
52 |
return false; |
53 |
ReadableVectorial adapter = getLayer().getSource(); |
54 |
int type=FShape.POINT;
|
55 |
try {
|
56 |
type=adapter.getShapeType(); |
57 |
} catch (ReadDriverException e) {
|
58 |
NotificationManager.addError(e); |
59 |
} |
60 |
return (getType()==IOperator.NUMBER && type==FShape.POINT);
|
61 |
} |
62 |
public String getTooltip(){ |
63 |
return "operator"+": "+addText("")+"\n"+getDescription(); |
64 |
} |
65 |
public String getDescription() { |
66 |
return "returns" + ": " + |
67 |
"numeric_value" + "\n" + |
68 |
"description" + ": " + |
69 |
"Returns the X coordenate of point geometry of this row.";
|
70 |
} |
71 |
} |