Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / operators / PointY.java @ 27752

History | View | Annotate | Download (2.61 KB)

1
package com.iver.cit.gvsig.project.documents.table.operators;
2

    
3
import java.util.ArrayList;
4

    
5
import org.apache.bsf.BSFException;
6
import org.apache.bsf.BSFManager;
7
import org.gvsig.fmap.dal.exception.DataException;
8
import org.gvsig.fmap.dal.feature.Feature;
9
import org.gvsig.fmap.dal.feature.FeatureStore;
10

    
11
import com.iver.andami.PluginServices;
12
import com.iver.andami.messages.NotificationManager;
13
import com.iver.cit.gvsig.ExpressionFieldExtension;
14
import com.iver.cit.gvsig.project.documents.table.GraphicOperator;
15
import com.iver.cit.gvsig.project.documents.table.IOperator;
16
/**
17
 * @author Vicente Caballero Navarro
18
 */
19
public class PointY extends GraphicOperator{
20

    
21
        public String addText(String s) {
22
                return s.concat(toString()+"()");
23
        }
24
        public double process(Feature feature) {
25
//                ReadableVectorial adapter = getLayer().getSource();
26
                org.gvsig.fmap.geom.Geometry geom=null;
27
//                try {
28
                        geom = feature.getDefaultGeometry();//adapter.getShape(index.get());
29
//                } catch (ExpansionFileReadException e) {
30
//                        throw new DriverIOException(e);
31
//                } catch (ReadDriverException e) {
32
//                        throw new DriverIOException(e);
33
//                }
34
                ArrayList parts=getXY(geom);
35
                Double[][] xsys=(Double[][])parts.get(0);//getXY(geom);
36
                return xsys[1][0].doubleValue();
37
        }
38
        public void eval(BSFManager interpreter) throws BSFException {
39
                interpreter.declareBean("pointY",this,PointY.class);
40
//                interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double y(){return pointY.process(indexRow);};");
41
                interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def y():\n" +
42
                                "  return pointY.process(featureContainer.getFeature())");
43
        }
44
        public String toString() {
45
                return "y";
46
        }
47
        public boolean isEnable() {
48
                if (getLayer()==null)
49
                        return false;
50
                int geomType=org.gvsig.fmap.geom.Geometry.TYPES.POINT;
51
                try {
52
                        FeatureStore store = getLayer().getFeatureStore();
53
                        geomType = store.getDefaultFeatureType().getAttributeDescriptor(store.getDefaultFeatureType().getDefaultGeometryAttributeIndex()).getGeometryType();
54
                } catch (DataException e) {
55
                        NotificationManager.addError(e);
56
                }
57
                return (getType()==IOperator.NUMBER && geomType==org.gvsig.fmap.geom.Geometry.TYPES.POINT);
58
        }
59
        public String getTooltip(){
60
                return PluginServices.getText(this,"operator")+":  "+addText("")+"\n"+getDescription();
61
        }
62
        public String getDescription() {
63
        return PluginServices.getText(this, "returns") + ": " +
64
        PluginServices.getText(this, "numeric_value") + "\n" +
65
        PluginServices.getText(this, "description") + ": " +
66
        "Returns the Y coordenate of point geometry of this row.";
67
    }
68
}