svn-gvsig-desktop / tags / v2_0_0_Build_2060 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / ContainsGeometryEvaluator.java @ 39366
History | View | Annotate | Download (3.07 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 |
|
43 |
IProjection fad_proj = fad.getSRS(); |
44 |
ICoordTrans ct = null;
|
45 |
if (fad_proj != null && !fad_proj.equals(projection)) { |
46 |
ct = projection.getCT(fad_proj); |
47 |
} |
48 |
|
49 |
if (ct != null) { |
50 |
geometryTrans.reProject(ct); |
51 |
} |
52 |
this.geomName = geomName;
|
53 |
|
54 |
this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
55 |
|
56 |
} |
57 |
|
58 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
59 |
try {
|
60 |
DefaultRelationshipGeometryOperationContext context; |
61 |
if (isDefault) {
|
62 |
Feature feature = (Feature) data.getContextValue("feature");
|
63 |
context =new DefaultRelationshipGeometryOperationContext(feature
|
64 |
.getDefaultGeometry()); |
65 |
|
66 |
} else {
|
67 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
68 |
|
69 |
context = new DefaultRelationshipGeometryOperationContext(geom);
|
70 |
} |
71 |
return geometryTrans.invokeOperation(Contains.CODE, context);
|
72 |
|
73 |
} catch (Exception e) { |
74 |
throw new EvaluatorException(e); |
75 |
} |
76 |
} |
77 |
|
78 |
public String getName() { |
79 |
return "contains with geometry"; |
80 |
} |
81 |
|
82 |
public String getSQL() { |
83 |
if (geometryWKT == null) { |
84 |
try {
|
85 |
geometryWKT = (String) geometry.invokeOperation(ToWKT.CODE,
|
86 |
null);
|
87 |
} catch (GeometryOperationNotSupportedException e) {
|
88 |
throw new DataEvaluatorRuntimeException(e); |
89 |
} catch (GeometryOperationException e) {
|
90 |
throw new DataEvaluatorRuntimeException(e); |
91 |
} |
92 |
} |
93 |
|
94 |
return " contains(GeomFromText('" + geometryWKT + "', " + "'" |
95 |
+ srs + "'" + "), " + geomName + ") "; |
96 |
} |
97 |
|
98 |
} |