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