svn-gvsig-desktop / tags / v2_0_0_Build_2060 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / WithinGeometryEvaluator.java @ 39366
History | View | Annotate | Download (2.5 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 |
|
38 |
IProjection fad_proj = fad.getSRS(); |
39 |
ICoordTrans ct = null;
|
40 |
|
41 |
if (fad_proj != null && !fad_proj.equals(envelopeProjection)) { |
42 |
ct = envelopeProjection.getCT(fad_proj); |
43 |
} |
44 |
|
45 |
if (ct != null) { |
46 |
geometryTrans.reProject(ct); |
47 |
} |
48 |
this.geomName = geomName;
|
49 |
|
50 |
this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
51 |
|
52 |
} |
53 |
|
54 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
55 |
try {
|
56 |
DefaultRelationshipGeometryOperationContext context; |
57 |
if (isDefault) {
|
58 |
Feature feature = (Feature) data.getContextValue("feature");
|
59 |
context =new DefaultRelationshipGeometryOperationContext(feature
|
60 |
.getDefaultGeometry()); |
61 |
|
62 |
} else {
|
63 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
64 |
|
65 |
context = new DefaultRelationshipGeometryOperationContext(geom);
|
66 |
} |
67 |
return geometryTrans.invokeOperation(Within.CODE, context);
|
68 |
|
69 |
} catch (Exception e) { |
70 |
throw new EvaluatorException(e); |
71 |
} |
72 |
} |
73 |
|
74 |
public String getName() { |
75 |
return "within with geometry"; |
76 |
} |
77 |
|
78 |
public String getSQL() { |
79 |
return " within(GeomFromText('" + geometry.toString() + "', " + "'" |
80 |
+ srs + "'" + "), " + geomName + ") "; |
81 |
} |
82 |
|
83 |
} |