root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / ContainsEnvelopeEvaluator.java @ 33053
History | View | Annotate | Download (2.84 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 ContainsEnvelopeEvaluator extends AbstractEvaluator { |
18 |
|
19 |
private Envelope envelope;
|
20 |
private String geomName; |
21 |
private Envelope envelopeTrans;
|
22 |
private boolean isDefault; |
23 |
private String srs; |
24 |
private String envelopeWKT; |
25 |
|
26 |
public ContainsEnvelopeEvaluator(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 |
this.srs = envelopeProjection.getAbrev();
|
49 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
50 |
|
51 |
} |
52 |
|
53 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
54 |
Envelope featureEnvelope; |
55 |
if (isDefault) {
|
56 |
featureEnvelope = ((Feature) data.getContextValue("feature"))
|
57 |
.getDefaultEnvelope(); |
58 |
|
59 |
} else {
|
60 |
featureEnvelope = ((Geometry) data.getDataValue(geomName)) |
61 |
.getEnvelope(); |
62 |
} |
63 |
return new Boolean(envelopeTrans.contains(featureEnvelope)); |
64 |
} |
65 |
|
66 |
public String getName() { |
67 |
return "contains in envelope"; |
68 |
} |
69 |
|
70 |
public String getSQL() { |
71 |
if (envelopeWKT == null) { |
72 |
try {
|
73 |
envelopeWKT = (String) envelope.getGeometry().invokeOperation(
|
74 |
ToWKT.CODE, null);
|
75 |
} catch (GeometryOperationNotSupportedException e) {
|
76 |
throw new DataEvaluatorRuntimeException(e); |
77 |
} catch (GeometryOperationException e) {
|
78 |
throw new DataEvaluatorRuntimeException(e); |
79 |
} |
80 |
} |
81 |
return " contains(GeomFromText('" + envelope.toString() + "', " + "'" |
82 |
+ srs + "'" + "), boundary(" + geomName + ")) "; |
83 |
} |
84 |
|
85 |
} |