svn-gvsig-desktop / tags / v2_0_0_Build_2059 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / IntersectsGeometryEvaluator.java @ 39314
History | View | Annotate | Download (3.02 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 = null;
|
39 |
|
40 |
IProjection ipro = fad.getSRS(); |
41 |
if (ipro != null && !ipro.equals(projection)) { |
42 |
ct = projection.getCT(ipro); |
43 |
} |
44 |
|
45 |
if (ct != null) { |
46 |
geometryTrans.reProject(ct); |
47 |
} |
48 |
this.geomName = geomName;
|
49 |
|
50 |
this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
51 |
|
52 |
} |
53 |
|
54 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
55 |
try {
|
56 |
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 |
} |
72 |
} |
73 |
|
74 |
public String getName() { |
75 |
return "intersects with geometry"; |
76 |
} |
77 |
|
78 |
public String getSQL() { |
79 |
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 |
+ srs + "'" + "), " + geomName + ") "; |
91 |
} |
92 |
|
93 |
} |