svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / CrossesGeometryEvaluator.java @ 28076
History | View | Annotate | Download (2.95 KB)
1 | 26438 | 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 | 26438 | vcaballero | 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 | 28074 | jmvivo | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
11 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
12 | 26438 | vcaballero | import org.gvsig.fmap.geom.operation.relationship.Crosses; |
13 | import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
||
14 | 28074 | jmvivo | import org.gvsig.fmap.geom.operation.towkt.ToWKT; |
15 | 26438 | vcaballero | import org.gvsig.tools.evaluator.AbstractEvaluator; |
16 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
17 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
18 | /**
|
||
19 | *
|
||
20 | * @author Vicente Caballero Navarro
|
||
21 | *
|
||
22 | */
|
||
23 | public class CrossesGeometryEvaluator extends AbstractEvaluator { |
||
24 | |||
25 | private String geomName; |
||
26 | private Geometry geometry;
|
||
27 | private Geometry geometryTrans;
|
||
28 | private String srs; |
||
29 | private boolean isDefault; |
||
30 | 28074 | jmvivo | private String geometryWKT; |
31 | 26438 | vcaballero | |
32 | public CrossesGeometryEvaluator(Geometry geometry,
|
||
33 | 28074 | jmvivo | IProjection projection, FeatureType featureType, |
34 | 26438 | vcaballero | String geomName) {
|
35 | FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
||
36 | .get(geomName); |
||
37 | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
||
38 | geomName); |
||
39 | this.geometry = geometry;
|
||
40 | this.geometryTrans = geometry.cloneGeometry();
|
||
41 | 28074 | jmvivo | this.srs = projection.getAbrev();
|
42 | ICoordTrans ct = projection.getCT(fad.getSRS()); |
||
43 | 26438 | vcaballero | if (ct != null) { |
44 | geometryTrans.reProject(ct); |
||
45 | } |
||
46 | this.geomName = geomName;
|
||
47 | |||
48 | this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
||
49 | |||
50 | } |
||
51 | |||
52 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
53 | try {
|
||
54 | DefaultRelationshipGeometryOperationContext context; |
||
55 | if (isDefault) {
|
||
56 | Feature feature = (Feature) data.getContextValue("feature");
|
||
57 | context =new DefaultRelationshipGeometryOperationContext(feature
|
||
58 | .getDefaultGeometry()); |
||
59 | |||
60 | } else {
|
||
61 | Geometry geom = (Geometry) data.getDataValue(geomName); |
||
62 | |||
63 | context = new DefaultRelationshipGeometryOperationContext(geom);
|
||
64 | } |
||
65 | return geometryTrans.invokeOperation(Crosses.CODE, context);
|
||
66 | |||
67 | } catch (Exception e) { |
||
68 | throw new EvaluatorException(e); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | public String getName() { |
||
73 | return "crosses with geometry"; |
||
74 | } |
||
75 | |||
76 | public String getCQL() { |
||
77 | 28074 | jmvivo | if (geometryWKT == null) { |
78 | try {
|
||
79 | geometryWKT = (String) geometry.invokeOperation(ToWKT.CODE,
|
||
80 | null);
|
||
81 | } catch (GeometryOperationNotSupportedException e) {
|
||
82 | throw new DataEvaluatorRuntimeException(e); |
||
83 | } catch (GeometryOperationException e) {
|
||
84 | throw new DataEvaluatorRuntimeException(e); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | return " crosses(GeomFromText('" + geometryWKT + "', " + "'" |
||
89 | 26438 | vcaballero | + srs + "'" + "), " + geomName + ") "; |
90 | } |
||
91 | |||
92 | } |