root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / ContainsGeometryEvaluator.java @ 38605
History | View | Annotate | Download (2.95 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.Contains; |
13 |
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
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 |
*
|
20 |
* @author Vicente Caballero Navarro
|
21 |
*
|
22 |
*/
|
23 |
public class ContainsGeometryEvaluator extends AbstractEvaluator { |
24 |
|
25 |
private String geomName; |
26 |
private Geometry geometry;
|
27 |
private Geometry geometryTrans;
|
28 |
private String srs; |
29 |
private boolean isDefault; |
30 |
private String geometryWKT; |
31 |
|
32 |
public ContainsGeometryEvaluator(Geometry geometry,
|
33 |
IProjection projection, FeatureType featureType, |
34 |
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 |
this.srs = projection.getAbrev();
|
42 |
ICoordTrans ct = projection.getCT(fad.getSRS()); |
43 |
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(Contains.CODE, context);
|
66 |
|
67 |
} catch (Exception e) { |
68 |
throw new EvaluatorException(e); |
69 |
} |
70 |
} |
71 |
|
72 |
public String getName() { |
73 |
return "contains with geometry"; |
74 |
} |
75 |
|
76 |
public String getSQL() { |
77 |
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 " contains(GeomFromText('" + geometryWKT + "', " + "'" |
89 |
+ srs + "'" + "), " + geomName + ") "; |
90 |
} |
91 |
|
92 |
} |