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