Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / IntersectsGeometryEvaluator.java @ 38557

History | View | Annotate | Download (3 KB)

1 24797 vcaballero
package org.gvsig.fmap.mapcontext.layers.vectorial;
2
3
import org.cresques.cts.ICoordTrans;
4
import org.cresques.cts.IProjection;
5 28074 jmvivo
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
6 25242 jmvivo
import org.gvsig.fmap.dal.feature.Feature;
7 24797 vcaballero
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
8
import org.gvsig.fmap.dal.feature.FeatureType;
9
import org.gvsig.fmap.geom.Geometry;
10 28074 jmvivo
import org.gvsig.fmap.geom.operation.GeometryOperationException;
11
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
12 24797 vcaballero
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext;
13
import org.gvsig.fmap.geom.operation.relationship.Intersects;
14 28074 jmvivo
import org.gvsig.fmap.geom.operation.towkt.ToWKT;
15 24797 vcaballero
import org.gvsig.tools.evaluator.AbstractEvaluator;
16
import org.gvsig.tools.evaluator.EvaluatorData;
17
import org.gvsig.tools.evaluator.EvaluatorException;
18
19
public class IntersectsGeometryEvaluator extends AbstractEvaluator {
20
21
        private String geomName;
22 25242 jmvivo
        private Geometry geometry;
23 28074 jmvivo
        private String geometryWKT = null;
24 24797 vcaballero
        private Geometry geometryTrans;
25
        private String srs;
26 25242 jmvivo
        private boolean isDefault;
27 24797 vcaballero
28
        public IntersectsGeometryEvaluator(Geometry geometry,
29 28074 jmvivo
                        IProjection projection, FeatureType featureType,
30 24797 vcaballero
                        String geomName) {
31
                FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
32
                                .get(geomName);
33 25242 jmvivo
                this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
34
                                geomName);
35 24797 vcaballero
                this.geometry = geometry;
36
                this.geometryTrans = geometry.cloneGeometry();
37 28074 jmvivo
                this.srs = projection.getAbrev();
38 38557 jldominguez
                ICoordTrans ct = null;
39
40
                IProjection ipro = fad.getSRS();
41
                if (ipro != null) {
42
                    ct = projection.getCT(ipro);
43
                }
44
45 25242 jmvivo
                if (ct != null) {
46 24797 vcaballero
                        geometryTrans.reProject(ct);
47 25242 jmvivo
                }
48 24797 vcaballero
                this.geomName = geomName;
49
50 26325 jmvivo
                this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
51
52 24797 vcaballero
        }
53
54
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
55
                try {
56 25242 jmvivo
                        DefaultRelationshipGeometryOperationContext context;
57
                        if (isDefault) {
58
                                Feature feature = (Feature) data.getContextValue("feature");
59
                                context =new DefaultRelationshipGeometryOperationContext(feature
60
                                                .getDefaultGeometry());
61
62
                        } else {
63
                                Geometry geom = (Geometry) data.getDataValue(geomName);
64
65
                                context = new DefaultRelationshipGeometryOperationContext(geom);
66
                        }
67
                        return geometryTrans.invokeOperation(Intersects.CODE, context);
68
69
                } catch (Exception e) {
70
                        throw new EvaluatorException(e);
71 24797 vcaballero
                }
72
        }
73
74
        public String getName() {
75
                return "intersects with geometry";
76
        }
77
78 33053 cordinyana
        public String getSQL() {
79 28074 jmvivo
                if (geometryWKT == null) {
80
                        try {
81
                                geometryWKT = (String) geometry.invokeOperation(ToWKT.CODE,
82
                                                null);
83
                        } catch (GeometryOperationNotSupportedException e) {
84
                                throw new DataEvaluatorRuntimeException(e);
85
                        } catch (GeometryOperationException e) {
86
                                throw new DataEvaluatorRuntimeException(e);
87
                        }
88
                }
89
                return " intersects(GeomFromText('" + geometryWKT + "', " + "'"
90 25242 jmvivo
                                + srs + "'" + "), " + geomName + ") ";
91
        }
92
93 24797 vcaballero
}