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