root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / CrossEnvelopeEvaluator.java @ 38557
History | View | Annotate | Download (3.7 KB)
1 | 27267 | vcaballero | package org.gvsig.fmap.mapcontext.layers.vectorial; |
---|---|---|---|
2 | |||
3 | import org.cresques.cts.IProjection; |
||
4 | 34139 | cordinyana | |
5 | 28074 | jmvivo | import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
6 | 27267 | vcaballero | 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 | 28074 | jmvivo | 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 | 27267 | vcaballero | 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 | 28074 | jmvivo | private String envelopeWKT; |
26 | 27267 | vcaballero | |
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 | 28074 | jmvivo | this.geomName = geomName;
|
49 | this.srs = envelopeProjection.getAbrev();
|
||
50 | 27267 | vcaballero | |
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 | 33053 | cordinyana | public String getSQL() { |
91 | 28074 | jmvivo | 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 | 34139 | cordinyana | return " intersects(GeomFromText('" + envelopeWKT + "', '" + srs |
104 | + "'), envelope(" + geomName + ")) "; |
||
105 | 27267 | vcaballero | } |
106 | |||
107 | } |