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 / CrossEnvelopeEvaluator.java @ 43034
History | View | Annotate | Download (3.98 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 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 |
*
|
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 |
*
|
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.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
24 |
|
25 |
import org.cresques.cts.IProjection; |
26 |
import org.gvsig.fmap.dal.ExpressionBuilder; |
27 |
|
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.primitive.Envelope; |
33 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
34 |
import org.gvsig.tools.evaluator.EvaluatorData; |
35 |
import org.gvsig.tools.evaluator.EvaluatorException; |
36 |
|
37 |
public class CrossEnvelopeEvaluator extends AbstractEvaluator { |
38 |
|
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; |
45 |
|
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); |
55 |
|
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;
|
63 |
// ICoordTrans ct = null;
|
64 |
// if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n
|
65 |
// ct = envelopeProjection.getCT(fad.getSRS());
|
66 |
// }
|
67 |
// if (ct != null) {
|
68 |
// this.envelopeTrans = envelope.convert(ct);
|
69 |
// } else {
|
70 |
this.envelopeTrans = envelope;
|
71 |
// }
|
72 |
this.geomName = geomName;
|
73 |
|
74 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
75 |
|
76 |
} |
77 |
|
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;
|
88 |
|
89 |
} else {
|
90 |
Geometry geom = (Geometry) data.getDataValue(geomName); |
91 |
if (geom == null) { |
92 |
return Boolean.FALSE; |
93 |
} |
94 |
return envelopeTrans.intersects(geom.getEnvelope());
|
95 |
|
96 |
} |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public String getName() { |
101 |
return "contains in envelope"; |
102 |
} |
103 |
|
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 |
} |
113 |
} |