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