svn-gvsig-desktop / branches / dal_time_support / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / CrossEnvelopeEvaluator.java @ 37204
History | View | Annotate | Download (3.7 KB)
1 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
---|---|
2 |
|
3 |
import org.cresques.cts.IProjection; |
4 |
|
5 |
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
6 |
import org.gvsig.fmap.dal.feature.Feature; |
7 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
8 |
import org.gvsig.fmap.dal.feature.FeatureType; |
9 |
import org.gvsig.fmap.geom.Geometry; |
10 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
11 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
12 |
import org.gvsig.fmap.geom.operation.towkt.ToWKT; |
13 |
import org.gvsig.fmap.geom.primitive.Envelope; |
14 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
15 |
import org.gvsig.tools.evaluator.EvaluatorData; |
16 |
import org.gvsig.tools.evaluator.EvaluatorException; |
17 |
|
18 |
public class CrossEnvelopeEvaluator extends AbstractEvaluator { |
19 |
|
20 |
private Envelope envelope;
|
21 |
private String geomName; |
22 |
private Envelope envelopeTrans;
|
23 |
private boolean isDefault; |
24 |
private String srs; |
25 |
private String envelopeWKT; |
26 |
|
27 |
public CrossEnvelopeEvaluator(Envelope envelope,
|
28 |
IProjection envelopeProjection, FeatureType featureType, |
29 |
String geomName) {
|
30 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
31 |
.get(geomName); |
32 |
|
33 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
34 |
geomName); |
35 |
this.envelope = envelope;
|
36 |
// this.srs = envelopeProjection.getAbrev();
|
37 |
// this.projection=CRSFactory.getCRS(fad.getSRS());
|
38 |
// this.envelopeProjection=envelopeProjection;
|
39 |
// ICoordTrans ct = null;
|
40 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci?n
|
41 |
// ct = envelopeProjection.getCT(fad.getSRS());
|
42 |
// }
|
43 |
// if (ct != null) {
|
44 |
// this.envelopeTrans = envelope.convert(ct);
|
45 |
// } else {
|
46 |
this.envelopeTrans = envelope;
|
47 |
// }
|
48 |
this.geomName = geomName;
|
49 |
this.srs = envelopeProjection.getAbrev();
|
50 |
|
51 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
52 |
|
53 |
} |
54 |
|
55 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
56 |
if (isDefault) {
|
57 |
Feature feature = (Feature) data.getContextValue("feature");
|
58 |
// return new Boolean(envelopeTrans.contains(feature
|
59 |
// .getDefaultEnvelope())
|
60 |
// || envelopeTrans.intersects(feature.getDefaultEnvelope()));
|
61 |
// System.out.println("== Filter[" + envelopeTrans.getLowerCorner()[0]
|
62 |
// + "," + envelopeTrans.getLowerCorner()[1] + "] ["
|
63 |
// + envelopeTrans.getUpperCorner()[0] + ","
|
64 |
// + envelopeTrans.getUpperCorner()[1] + "]");
|
65 |
|
66 |
Envelope featureEnvelope = feature.getDefaultEnvelope(); |
67 |
// System.out.println("== Geom ["
|
68 |
// + featureEnvelope.getLowerCorner()[0]
|
69 |
// + "," + featureEnvelope.getLowerCorner()[1] + "] ["
|
70 |
// + featureEnvelope.getUpperCorner()[0] + ","
|
71 |
// + featureEnvelope.getUpperCorner()[1] + "]");
|
72 |
Boolean r = new Boolean(envelopeTrans.intersects(featureEnvelope)); |
73 |
// System.out.println("==3 "+r);
|
74 |
return r;
|
75 |
|
76 |
} else {
|
77 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
78 |
// return new Boolean(envelopeTrans.contains(geom.getEnvelope())
|
79 |
// || envelopeTrans.intersects(geom.getEnvelope()));
|
80 |
|
81 |
return new Boolean(envelopeTrans.intersects(geom.getEnvelope())); |
82 |
|
83 |
} |
84 |
} |
85 |
|
86 |
public String getName() { |
87 |
return "contains in envelope"; |
88 |
} |
89 |
|
90 |
public String getSQL() { |
91 |
if (envelopeWKT == null) { |
92 |
try {
|
93 |
envelopeWKT = (String) envelope.getGeometry().invokeOperation(
|
94 |
ToWKT.CODE, |
95 |
null);
|
96 |
} catch (GeometryOperationNotSupportedException e) {
|
97 |
throw new DataEvaluatorRuntimeException(e); |
98 |
} catch (GeometryOperationException e) {
|
99 |
throw new DataEvaluatorRuntimeException(e); |
100 |
} |
101 |
} |
102 |
|
103 |
return " intersects(GeomFromText('" + envelopeWKT + "', '" + srs |
104 |
+ "'), envelope(" + geomName + ")) "; |
105 |
} |
106 |
|
107 |
} |