Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / EqualsGeometryEvaluator.java @ 40372

History | View | Annotate | Download (2.66 KB)

1
package org.gvsig.fmap.mapcontext.layers.vectorial;
2

    
3
import org.cresques.cts.ICoordTrans;
4
import org.cresques.cts.IProjection;
5
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
6
import org.gvsig.fmap.dal.feature.Feature;
7
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
8
import org.gvsig.fmap.dal.feature.FeatureType;
9
import org.gvsig.fmap.geom.Geometry;
10
import org.gvsig.fmap.geom.operation.GeometryOperationException;
11
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
12
import org.gvsig.tools.evaluator.AbstractEvaluator;
13
import org.gvsig.tools.evaluator.EvaluatorData;
14
import org.gvsig.tools.evaluator.EvaluatorException;
15
/**
16
 *
17
 * @author Vicente Caballero Navarro
18
 *
19
 */
20
public class EqualsGeometryEvaluator extends AbstractEvaluator {
21

    
22
        private String geomName;
23
        private Geometry geometry;
24
        private String geometryWKT = null;
25
        private Geometry geometryTrans;
26
        private String srs;
27
        private boolean isDefault;
28

    
29
        public EqualsGeometryEvaluator(Geometry geometry,
30
                        IProjection projection, FeatureType featureType,
31
                        String geomName) {
32
                FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
33
                                .get(geomName);
34
                this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
35
                                geomName);
36
                this.geometry = geometry;
37
                this.geometryTrans = geometry.cloneGeometry();
38
                this.srs = projection.getAbrev();
39
                
40
                IProjection fad_proj = fad.getSRS();
41
                ICoordTrans ct = null;
42
                
43
                if (fad_proj != null && !fad_proj.equals(projection)) {
44
                    ct = projection.getCT(fad_proj);
45
                }
46

    
47
                if (ct != null) {
48
                        geometryTrans.reProject(ct);
49
                }
50
                this.geomName = geomName;
51

    
52
                this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
53

    
54
        }
55

    
56
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
57
                try {
58
                        Geometry geom = null;
59
                        if (isDefault) {
60
                                Feature feature = (Feature) data.getContextValue("feature");
61
                                geom =feature.getDefaultGeometry();
62

    
63
                        } else {
64
                                geom = (Geometry) data.getDataValue(geomName);
65
                        }
66
                        return new Boolean(geometryTrans.equals(geom));
67

    
68
                } catch (Exception e) {
69
                        throw new EvaluatorException(e);
70
                }
71
        }
72

    
73
        public String getName() {
74
                return "equals with geometry";
75
        }
76

    
77
        public String getSQL() {
78
                if (geometryWKT == null) {
79
                        try {
80
                                geometryWKT = geometry.convertToWKT();
81
                        } catch (GeometryOperationNotSupportedException e) {
82
                                throw new DataEvaluatorRuntimeException(e);
83
                        } catch (GeometryOperationException e) {
84
                                throw new DataEvaluatorRuntimeException(e);
85
                        }
86
                }
87
                return " equals(GeomFromText('" + geometryWKT + "', " + "'"
88
                                + srs + "'" + "), " + geomName + ") ";
89
        }
90

    
91
}