root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / CrossEnvelopeEvaluator.java @ 33053
History | View | Annotate | Download (3.71 KB)
1 | 27267 | vcaballero | package org.gvsig.fmap.mapcontext.layers.vectorial; |
---|---|---|---|
2 | |||
3 | import org.cresques.cts.IProjection; |
||
4 | 28074 | jmvivo | import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
5 | 27267 | vcaballero | 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 | 28074 | jmvivo | 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 | 27267 | vcaballero | 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 CrossEnvelopeEvaluator extends AbstractEvaluator { |
||
18 | |||
19 | private Envelope envelope;
|
||
20 | private String geomName; |
||
21 | private Envelope envelopeTrans;
|
||
22 | private boolean isDefault; |
||
23 | private String srs; |
||
24 | 28074 | jmvivo | private String envelopeWKT; |
25 | 27267 | vcaballero | |
26 | public CrossEnvelopeEvaluator(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 | 28074 | jmvivo | this.geomName = geomName;
|
48 | this.srs = envelopeProjection.getAbrev();
|
||
49 | 27267 | vcaballero | |
50 | this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
||
51 | |||
52 | } |
||
53 | |||
54 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
55 | if (isDefault) {
|
||
56 | Feature feature = (Feature) data.getContextValue("feature");
|
||
57 | // return new Boolean(envelopeTrans.contains(feature
|
||
58 | // .getDefaultEnvelope())
|
||
59 | // || envelopeTrans.intersects(feature.getDefaultEnvelope()));
|
||
60 | // System.out.println("== Filter[" + envelopeTrans.getLowerCorner()[0]
|
||
61 | // + "," + envelopeTrans.getLowerCorner()[1] + "] ["
|
||
62 | // + envelopeTrans.getUpperCorner()[0] + ","
|
||
63 | // + envelopeTrans.getUpperCorner()[1] + "]");
|
||
64 | |||
65 | Envelope featureEnvelope = feature.getDefaultEnvelope(); |
||
66 | // System.out.println("== Geom ["
|
||
67 | // + featureEnvelope.getLowerCorner()[0]
|
||
68 | // + "," + featureEnvelope.getLowerCorner()[1] + "] ["
|
||
69 | // + featureEnvelope.getUpperCorner()[0] + ","
|
||
70 | // + featureEnvelope.getUpperCorner()[1] + "]");
|
||
71 | Boolean r = new Boolean(envelopeTrans.intersects(featureEnvelope)); |
||
72 | // System.out.println("==3 "+r);
|
||
73 | return r;
|
||
74 | |||
75 | } else {
|
||
76 | Geometry geom = (Geometry) data.getDataValue(geomName); |
||
77 | // return new Boolean(envelopeTrans.contains(geom.getEnvelope())
|
||
78 | // || envelopeTrans.intersects(geom.getEnvelope()));
|
||
79 | |||
80 | return new Boolean(envelopeTrans.intersects(geom.getEnvelope())); |
||
81 | |||
82 | } |
||
83 | } |
||
84 | |||
85 | public String getName() { |
||
86 | return "contains in envelope"; |
||
87 | } |
||
88 | |||
89 | 33053 | cordinyana | public String getSQL() { |
90 | 28074 | jmvivo | if (envelopeWKT == null) { |
91 | try {
|
||
92 | envelopeWKT = (String) envelope.getGeometry().invokeOperation(
|
||
93 | ToWKT.CODE, |
||
94 | null);
|
||
95 | } catch (GeometryOperationNotSupportedException e) {
|
||
96 | throw new DataEvaluatorRuntimeException(e); |
||
97 | } catch (GeometryOperationException e) {
|
||
98 | throw new DataEvaluatorRuntimeException(e); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | return " intersects(GeomFromText('" + envelopeWKT + "', " |
||
103 | + "'"
|
||
104 | 27267 | vcaballero | + srs + "'" + "), boundary(" + geomName + ")) "; |
105 | } |
||
106 | |||
107 | } |