root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / IntersectsEnvelopeEvaluator.java @ 38100
History | View | Annotate | Download (2.76 KB)
1 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
---|---|
2 |
|
3 |
import org.cresques.cts.IProjection; |
4 |
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
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.GeometryOperationException; |
10 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
11 |
import org.gvsig.fmap.geom.primitive.Envelope; |
12 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
13 |
import org.gvsig.tools.evaluator.EvaluatorData; |
14 |
import org.gvsig.tools.evaluator.EvaluatorException; |
15 |
|
16 |
public class IntersectsEnvelopeEvaluator extends AbstractEvaluator { |
17 |
|
18 |
private Envelope envelope;
|
19 |
private String geomName; |
20 |
private String envelopeWKT = null; |
21 |
private Envelope envelopeTrans;
|
22 |
private boolean isDefault; |
23 |
private String srs; |
24 |
|
25 |
public IntersectsEnvelopeEvaluator(Envelope envelope,
|
26 |
IProjection envelopeProjection, FeatureType featureType, |
27 |
String geomName) {
|
28 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
29 |
.get(geomName); |
30 |
|
31 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
32 |
geomName); |
33 |
this.envelope = envelope;
|
34 |
// this.srs = envelopeProjection.getAbrev();
|
35 |
// this.projection=CRSFactory.getCRS(fad.getSRS());
|
36 |
// this.envelopeProjection=envelopeProjection;
|
37 |
// ICoordTrans ct = null;
|
38 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci?n
|
39 |
// ct = envelopeProjection.getCT(fad.getSRS());
|
40 |
// }
|
41 |
// if (ct != null) {
|
42 |
// this.envelopeTrans = envelope.convert(ct);
|
43 |
// } else {
|
44 |
this.envelopeTrans = envelope;
|
45 |
// }
|
46 |
this.geomName = geomName;
|
47 |
|
48 |
this.srs = envelopeProjection.getAbrev();
|
49 |
|
50 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
51 |
|
52 |
} |
53 |
|
54 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
55 |
Envelope featureEnvelope; |
56 |
if (isDefault) {
|
57 |
featureEnvelope = ((Feature) data.getContextValue("feature"))
|
58 |
.getDefaultEnvelope(); |
59 |
} else {
|
60 |
featureEnvelope = ((Geometry) data.getDataValue(geomName)).getEnvelope(); |
61 |
} |
62 |
return new Boolean(envelopeTrans.intersects(featureEnvelope)); |
63 |
|
64 |
} |
65 |
|
66 |
public String getName() { |
67 |
return "intersets in envelope"; |
68 |
} |
69 |
|
70 |
public String getSQL() { |
71 |
|
72 |
if (envelopeWKT == null) { |
73 |
try {
|
74 |
envelopeWKT = (String) envelope.getGeometry().convertToWKT();
|
75 |
} catch (GeometryOperationNotSupportedException e) {
|
76 |
throw new DataEvaluatorRuntimeException(e); |
77 |
} catch (GeometryOperationException e) {
|
78 |
throw new DataEvaluatorRuntimeException(e); |
79 |
} |
80 |
} |
81 |
|
82 |
return " intersects(GeomFromText('" + envelopeWKT + "', '" + srs |
83 |
+ "'), envelope(" + geomName + ")) "; |
84 |
} |
85 |
|
86 |
} |