root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / OutGeometryEvaluator.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 OutGeometryEvaluator 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 OutGeometryEvaluator(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().addFieldValue(geomName);
|
49 |
|
50 |
} |
51 |
|
52 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
53 |
try {
|
54 |
Geometry geom = null;
|
55 |
if (isDefault) {
|
56 |
Feature feature = (Feature) data.getContextValue("feature");
|
57 |
geom = feature.getDefaultGeometry(); |
58 |
|
59 |
} else {
|
60 |
geom = (Geometry) data.getDataValue(geomName); |
61 |
} |
62 |
return new Boolean(!geometryTrans.contains(geom) && !geometryTrans.intersects(geom)); |
63 |
|
64 |
} catch (Exception e) { |
65 |
throw new EvaluatorException(e); |
66 |
} |
67 |
} |
68 |
|
69 |
public String getName() { |
70 |
return "out of geometry"; |
71 |
} |
72 |
|
73 |
public String getSQL() { |
74 |
return " not contains(GeomFromText('" + geometry.toString() + "', " + "'" |
75 |
+ srs + "'" + "), " + geomName + ") "; |
76 |
} |
77 |
|
78 |
} |