Revision 43040 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
ContainsEnvelopeEvaluator.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
25 | 24 |
|
26 | 25 |
import org.cresques.cts.IProjection; |
26 |
import org.gvsig.fmap.dal.ExpressionBuilder; |
|
27 | 27 |
|
28 |
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
|
29 | 28 |
import org.gvsig.fmap.dal.feature.Feature; |
30 | 29 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
31 | 30 |
import org.gvsig.fmap.dal.feature.FeatureType; |
32 | 31 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
35 | 32 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 | 33 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
37 | 34 |
import org.gvsig.tools.evaluator.EvaluatorData; |
... | ... | |
39 | 36 |
|
40 | 37 |
public class ContainsEnvelopeEvaluator extends AbstractEvaluator { |
41 | 38 |
|
42 |
private Envelope envelope;
|
|
43 |
private String geomName;
|
|
44 |
private Envelope envelopeTrans;
|
|
45 |
private boolean isDefault;
|
|
46 |
private String srs;
|
|
47 |
private String envelopeWKT;
|
|
39 |
private final Envelope envelope;
|
|
40 |
private final String geomName;
|
|
41 |
private final Envelope envelopeTrans;
|
|
42 |
private final boolean isDefault;
|
|
43 |
private final ExpressionBuilder builder;
|
|
44 |
private final IProjection projection;
|
|
48 | 45 |
|
49 |
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; |
|
46 |
/** |
|
47 |
* @deprecated use @{link org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory} |
|
48 |
* @param envelope |
|
49 |
* @param envelopeProjection |
|
50 |
* @param featureType |
|
51 |
* @param geomName |
|
52 |
*/ |
|
53 |
public ContainsEnvelopeEvaluator( |
|
54 |
Envelope envelope, |
|
55 |
IProjection envelopeProjection, |
|
56 |
FeatureType featureType, |
|
57 |
String geomName |
|
58 |
) { |
|
59 |
this( |
|
60 |
envelope, |
|
61 |
envelopeProjection, |
|
62 |
featureType, |
|
63 |
geomName, |
|
64 |
SpatialEvaluatorsFactory.getInstance().createBuilder() |
|
65 |
); |
|
66 |
} |
|
67 |
|
|
68 |
ContainsEnvelopeEvaluator( |
|
69 |
Envelope envelope, |
|
70 |
IProjection envelopeProjection, |
|
71 |
FeatureType featureType, |
|
72 |
String geomName, |
|
73 |
ExpressionBuilder builder |
|
74 |
) { |
|
75 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
|
76 |
.get(geomName); |
|
77 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName); |
|
78 |
this.projection = envelopeProjection; |
|
79 |
this.builder = builder; |
|
80 |
this.envelope = envelope; |
|
81 |
// this.srs = envelopeProjection.getAbrev(); |
|
82 |
// this.projection=CRSFactory.getCRS(fad.getSRS()); |
|
83 |
// this.envelopeProjection=envelopeProjection; |
|
61 | 84 |
// ICoordTrans ct = null; |
62 | 85 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n |
63 | 86 |
// ct = envelopeProjection.getCT(fad.getSRS()); |
... | ... | |
65 | 88 |
// if (ct != null) { |
66 | 89 |
// this.envelopeTrans = envelope.convert(ct); |
67 | 90 |
// } else { |
68 |
this.envelopeTrans = envelope;
|
|
91 |
this.envelopeTrans = envelope;
|
|
69 | 92 |
// } |
70 |
this.geomName = geomName; |
|
71 |
this.srs = envelopeProjection.getAbrev(); |
|
72 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans); |
|
93 |
this.geomName = geomName; |
|
94 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans); |
|
73 | 95 |
|
74 |
}
|
|
96 |
}
|
|
75 | 97 |
|
76 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
77 |
Envelope featureEnvelope; |
|
78 |
if (isDefault) { |
|
79 |
featureEnvelope = ((Feature) data.getContextValue("feature")) |
|
80 |
.getDefaultEnvelope(); |
|
98 |
@Override |
|
99 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
100 |
Envelope featureEnvelope; |
|
101 |
if (isDefault) { |
|
102 |
featureEnvelope = ((Feature) data.getContextValue("feature")) |
|
103 |
.getDefaultEnvelope(); |
|
81 | 104 |
|
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 |
}
|
|
105 |
} else {
|
|
106 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
|
107 |
if (geom == null) {
|
|
108 |
return false;
|
|
109 |
} |
|
110 |
featureEnvelope = geom.getEnvelope(); |
|
111 |
}
|
|
112 |
return envelopeTrans.contains(featureEnvelope);
|
|
113 |
}
|
|
91 | 114 |
|
92 |
public String getName() { |
|
93 |
return "contains in envelope"; |
|
94 |
} |
|
115 |
@Override |
|
116 |
public String getName() { |
|
117 |
return "contains in envelope"; |
|
118 |
} |
|
95 | 119 |
|
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 |
} |
|
120 |
@Override |
|
121 |
public String getSQL() { |
|
122 |
return this.builder.set( |
|
123 |
builder.ST_Contains( |
|
124 |
builder.envelope(envelope, projection), |
|
125 |
builder.column(geomName) |
|
126 |
) |
|
127 |
).toString(); |
|
128 |
} |
|
109 | 129 |
|
110 | 130 |
} |
Also available in: Unified diff