Revision 43034 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/CrossEnvelopeEvaluator.java
CrossEnvelopeEvaluator.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 CrossEnvelopeEvaluator 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 |
CrossEnvelopeEvaluator(Envelope envelope, |
|
50 |
IProjection envelopeProjection, FeatureType featureType, |
|
51 |
String geomName) { |
|
52 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
|
53 |
.get(geomName); |
|
46 |
CrossEnvelopeEvaluator( |
|
47 |
Envelope envelope, |
|
48 |
IProjection envelopeProjection, |
|
49 |
FeatureType featureType, |
|
50 |
String geomName, |
|
51 |
ExpressionBuilder builder |
|
52 |
) { |
|
53 |
FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
|
54 |
.get(geomName); |
|
54 | 55 |
|
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; |
|
56 |
this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName); |
|
57 |
this.envelope = envelope; |
|
58 |
this.projection = envelopeProjection; |
|
59 |
this.builder = builder; |
|
60 |
// this.srs = envelopeProjection.getAbrev(); |
|
61 |
// this.projection=CRSFactory.getCRS(fad.getSRS()); |
|
62 |
// this.envelopeProjection=envelopeProjection; |
|
61 | 63 |
// ICoordTrans ct = null; |
62 | 64 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n |
63 | 65 |
// ct = envelopeProjection.getCT(fad.getSRS()); |
... | ... | |
65 | 67 |
// if (ct != null) { |
66 | 68 |
// this.envelopeTrans = envelope.convert(ct); |
67 | 69 |
// } else { |
68 |
this.envelopeTrans = envelope;
|
|
70 |
this.envelopeTrans = envelope;
|
|
69 | 71 |
// } |
70 |
this.geomName = geomName; |
|
71 |
this.srs = envelopeProjection.getAbrev(); |
|
72 |
this.geomName = geomName; |
|
72 | 73 |
|
73 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
|
74 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
|
74 | 75 |
|
75 |
}
|
|
76 |
}
|
|
76 | 77 |
|
77 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
78 |
if (isDefault) { |
|
79 |
Feature feature = (Feature) data.getContextValue("feature"); |
|
80 |
Envelope featureEnvelope = feature.getDefaultEnvelope(); |
|
81 |
if( featureEnvelope == null ) { |
|
82 |
return Boolean.FALSE; |
|
83 |
} |
|
84 |
Boolean r = new Boolean(envelopeTrans.intersects(featureEnvelope)); |
|
85 |
return r; |
|
78 |
@Override |
|
79 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
80 |
if (isDefault) { |
|
81 |
Feature feature = (Feature) data.getContextValue("feature"); |
|
82 |
Envelope featureEnvelope = feature.getDefaultEnvelope(); |
|
83 |
if (featureEnvelope == null) { |
|
84 |
return Boolean.FALSE; |
|
85 |
} |
|
86 |
Boolean r = envelopeTrans.intersects(featureEnvelope); |
|
87 |
return r; |
|
86 | 88 |
|
87 |
} else {
|
|
88 |
Geometry geom = (Geometry) data.getDataValue(geomName);
|
|
89 |
if( geom == null ) {
|
|
90 |
return Boolean.FALSE;
|
|
91 |
}
|
|
92 |
return new Boolean(envelopeTrans.intersects(geom.getEnvelope()));
|
|
89 |
} else {
|
|
90 |
Geometry geom = (Geometry) data.getDataValue(geomName);
|
|
91 |
if (geom == null) {
|
|
92 |
return Boolean.FALSE; |
|
93 |
} |
|
94 |
return envelopeTrans.intersects(geom.getEnvelope());
|
|
93 | 95 |
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
}
|
|
96 | 98 |
|
97 |
public String getName() { |
|
98 |
return "contains in envelope"; |
|
99 |
} |
|
99 |
@Override |
|
100 |
public String getName() { |
|
101 |
return "contains in envelope"; |
|
102 |
} |
|
100 | 103 |
|
101 |
public String getSQL() { |
|
102 |
if (envelopeWKT == null) { |
|
103 |
try { |
|
104 |
envelopeWKT = envelope.getGeometry().convertToWKT(); |
|
105 |
} catch (GeometryOperationNotSupportedException e) { |
|
106 |
throw new DataEvaluatorRuntimeException(e); |
|
107 |
} catch (GeometryOperationException e) { |
|
108 |
throw new DataEvaluatorRuntimeException(e); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
return " ST_intersects(ST_GeomFromText('" + envelopeWKT + "', '" + srs |
|
113 |
+ "'), ST_envelope(" + geomName + ")) "; |
|
114 |
} |
|
115 |
|
|
104 |
@Override |
|
105 |
public String getSQL() { |
|
106 |
return this.builder.set( |
|
107 |
builder.ST_Intersects( |
|
108 |
builder.envelope(envelope, projection), |
|
109 |
builder.ST_Envelope(builder.column(geomName)) |
|
110 |
) |
|
111 |
).toString(); |
|
112 |
} |
|
116 | 113 |
} |
Also available in: Unified diff