root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / WithinGeometryEvaluator.java @ 38605
History | View | Annotate | Download (2.36 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.feature.Feature; |
6 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
7 |
import org.gvsig.fmap.dal.feature.FeatureType; |
8 |
import org.gvsig.fmap.geom.Geometry; |
9 |
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
10 |
import org.gvsig.fmap.geom.operation.relationship.Within; |
11 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
12 |
import org.gvsig.tools.evaluator.EvaluatorData; |
13 |
import org.gvsig.tools.evaluator.EvaluatorException; |
14 |
/**
|
15 |
*
|
16 |
* @author Vicente Caballero Navarro
|
17 |
*
|
18 |
*/
|
19 |
public class WithinGeometryEvaluator extends AbstractEvaluator { |
20 |
|
21 |
private String geomName; |
22 |
private Geometry geometry;
|
23 |
private Geometry geometryTrans;
|
24 |
private String srs; |
25 |
private boolean isDefault; |
26 |
|
27 |
public WithinGeometryEvaluator(Geometry geometry,
|
28 |
IProjection envelopeProjection, FeatureType featureType, |
29 |
String geomName) {
|
30 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
31 |
.get(geomName); |
32 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
33 |
geomName); |
34 |
this.geometry = geometry;
|
35 |
this.geometryTrans = geometry.cloneGeometry();
|
36 |
this.srs = envelopeProjection.getAbrev();
|
37 |
ICoordTrans ct = envelopeProjection.getCT(fad.getSRS()); |
38 |
if (ct != null) { |
39 |
geometryTrans.reProject(ct); |
40 |
} |
41 |
this.geomName = geomName;
|
42 |
|
43 |
this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
44 |
|
45 |
} |
46 |
|
47 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
48 |
try {
|
49 |
DefaultRelationshipGeometryOperationContext context; |
50 |
if (isDefault) {
|
51 |
Feature feature = (Feature) data.getContextValue("feature");
|
52 |
context =new DefaultRelationshipGeometryOperationContext(feature
|
53 |
.getDefaultGeometry()); |
54 |
|
55 |
} else {
|
56 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
57 |
|
58 |
context = new DefaultRelationshipGeometryOperationContext(geom);
|
59 |
} |
60 |
return geometryTrans.invokeOperation(Within.CODE, context);
|
61 |
|
62 |
} catch (Exception e) { |
63 |
throw new EvaluatorException(e); |
64 |
} |
65 |
} |
66 |
|
67 |
public String getName() { |
68 |
return "within with geometry"; |
69 |
} |
70 |
|
71 |
public String getSQL() { |
72 |
return " within(GeomFromText('" + geometry.toString() + "', " + "'" |
73 |
+ srs + "'" + "), " + geomName + ") "; |
74 |
} |
75 |
|
76 |
} |