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