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