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 / ContainsEnvelopeEvaluator.java @ 41348
History | View | Annotate | Download (3.87 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 |
|
28 |
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
29 |
import org.gvsig.fmap.dal.feature.Feature; |
30 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
31 |
import org.gvsig.fmap.dal.feature.FeatureType; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
37 |
import org.gvsig.tools.evaluator.EvaluatorData; |
38 |
import org.gvsig.tools.evaluator.EvaluatorException; |
39 |
|
40 |
public class ContainsEnvelopeEvaluator extends AbstractEvaluator { |
41 |
|
42 |
private Envelope envelope;
|
43 |
private String geomName; |
44 |
private Envelope envelopeTrans;
|
45 |
private boolean isDefault; |
46 |
private String srs; |
47 |
private String envelopeWKT; |
48 |
|
49 |
public ContainsEnvelopeEvaluator(Envelope envelope,
|
50 |
IProjection envelopeProjection, FeatureType featureType, |
51 |
String geomName) {
|
52 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
53 |
.get(geomName); |
54 |
|
55 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
56 |
geomName); |
57 |
this.envelope = envelope;
|
58 |
// this.srs = envelopeProjection.getAbrev();
|
59 |
// this.projection=CRSFactory.getCRS(fad.getSRS());
|
60 |
// this.envelopeProjection=envelopeProjection;
|
61 |
// ICoordTrans ct = null;
|
62 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n
|
63 |
// ct = envelopeProjection.getCT(fad.getSRS());
|
64 |
// }
|
65 |
// if (ct != null) {
|
66 |
// this.envelopeTrans = envelope.convert(ct);
|
67 |
// } else {
|
68 |
this.envelopeTrans = envelope;
|
69 |
// }
|
70 |
this.geomName = geomName;
|
71 |
this.srs = envelopeProjection.getAbrev();
|
72 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
73 |
|
74 |
} |
75 |
|
76 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
77 |
Envelope featureEnvelope; |
78 |
if (isDefault) {
|
79 |
featureEnvelope = ((Feature) data.getContextValue("feature"))
|
80 |
.getDefaultEnvelope(); |
81 |
|
82 |
} else {
|
83 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
84 |
if( geom == null ) { |
85 |
return Boolean.FALSE; |
86 |
} |
87 |
featureEnvelope = geom.getEnvelope(); |
88 |
} |
89 |
return new Boolean(envelopeTrans.contains(featureEnvelope)); |
90 |
} |
91 |
|
92 |
public String getName() { |
93 |
return "contains in envelope"; |
94 |
} |
95 |
|
96 |
public String getSQL() { |
97 |
if (envelopeWKT == null) { |
98 |
try {
|
99 |
envelopeWKT = envelope.getGeometry().convertToWKT(); |
100 |
} catch (GeometryOperationNotSupportedException e) {
|
101 |
throw new DataEvaluatorRuntimeException(e); |
102 |
} catch (GeometryOperationException e) {
|
103 |
throw new DataEvaluatorRuntimeException(e); |
104 |
} |
105 |
} |
106 |
return " ST_contains(ST_GeomFromText('" + envelopeWKT + "', '" + srs |
107 |
+ "'), ST_envelope(" + geomName + ")) "; |
108 |
} |
109 |
|
110 |
} |