svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / vectorial / IntersectsEnvelopeEvaluator.java @ 40559
History | View | Annotate | Download (3.73 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
28 |
import org.gvsig.fmap.dal.feature.Feature; |
29 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
30 |
import org.gvsig.fmap.dal.feature.FeatureType; |
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
34 |
import org.gvsig.fmap.geom.primitive.Envelope; |
35 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
36 |
import org.gvsig.tools.evaluator.EvaluatorData; |
37 |
import org.gvsig.tools.evaluator.EvaluatorException; |
38 |
|
39 |
public class IntersectsEnvelopeEvaluator extends AbstractEvaluator { |
40 |
|
41 |
private Envelope envelope;
|
42 |
private String geomName; |
43 |
private String envelopeWKT = null; |
44 |
private Envelope envelopeTrans;
|
45 |
private boolean isDefault; |
46 |
private String srs; |
47 |
|
48 |
public IntersectsEnvelopeEvaluator(Envelope envelope,
|
49 |
IProjection envelopeProjection, FeatureType featureType, |
50 |
String geomName) {
|
51 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
52 |
.get(geomName); |
53 |
|
54 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
55 |
geomName); |
56 |
this.envelope = envelope;
|
57 |
// this.srs = envelopeProjection.getAbrev();
|
58 |
// this.projection=CRSFactory.getCRS(fad.getSRS());
|
59 |
// this.envelopeProjection=envelopeProjection;
|
60 |
// ICoordTrans ct = null;
|
61 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci?n
|
62 |
// ct = envelopeProjection.getCT(fad.getSRS());
|
63 |
// }
|
64 |
// if (ct != null) {
|
65 |
// this.envelopeTrans = envelope.convert(ct);
|
66 |
// } else {
|
67 |
this.envelopeTrans = envelope;
|
68 |
// }
|
69 |
this.geomName = geomName;
|
70 |
|
71 |
this.srs = envelopeProjection.getAbrev();
|
72 |
|
73 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
74 |
|
75 |
} |
76 |
|
77 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
78 |
Envelope featureEnvelope; |
79 |
if (isDefault) {
|
80 |
featureEnvelope = ((Feature) data.getContextValue("feature"))
|
81 |
.getDefaultEnvelope(); |
82 |
} else {
|
83 |
featureEnvelope = ((Geometry) data.getDataValue(geomName)).getEnvelope(); |
84 |
} |
85 |
return new Boolean(envelopeTrans.intersects(featureEnvelope)); |
86 |
|
87 |
} |
88 |
|
89 |
public String getName() { |
90 |
return "intersects envelope"; |
91 |
} |
92 |
|
93 |
public String getSQL() { |
94 |
|
95 |
if (envelopeWKT == null) { |
96 |
try {
|
97 |
envelopeWKT = (String) envelope.getGeometry().convertToWKT();
|
98 |
} catch (GeometryOperationNotSupportedException e) {
|
99 |
throw new DataEvaluatorRuntimeException(e); |
100 |
} catch (GeometryOperationException e) {
|
101 |
throw new DataEvaluatorRuntimeException(e); |
102 |
} |
103 |
} |
104 |
|
105 |
return " ST_intersects(ST_GeomFromText('" + envelopeWKT + "', '" + srs |
106 |
+ "'), ST_envelope(" + geomName + ")) "; |
107 |
} |
108 |
|
109 |
} |