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 @ 44644
History | View | Annotate | Download (4.01 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.expressionevaluator.ExpressionBuilder; |
27 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
28 |
|
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.primitive.Envelope; |
34 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
35 |
import org.gvsig.tools.evaluator.EvaluatorData; |
36 |
import org.gvsig.tools.evaluator.EvaluatorException; |
37 |
|
38 |
public class IntersectsEnvelopeEvaluator extends AbstractEvaluator { |
39 |
|
40 |
private final Envelope envelope; |
41 |
private final String geomName; |
42 |
private final boolean isDefault; |
43 |
private final String defaultGeometryAttributeName; |
44 |
private final IProjection projection; |
45 |
private final GeometryExpressionBuilder builder; |
46 |
FeatureAttributeDescriptor fad; |
47 |
|
48 |
IntersectsEnvelopeEvaluator( |
49 |
Envelope envelope, |
50 |
IProjection envelopeProjection, |
51 |
FeatureType featureType, |
52 |
String geomName,
|
53 |
GeometryExpressionBuilder builder |
54 |
) { |
55 |
fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
56 |
defaultGeometryAttributeName = featureType.getDefaultGeometryAttributeName(); |
57 |
this.isDefault = defaultGeometryAttributeName.equals(geomName);
|
58 |
this.envelope = envelope;
|
59 |
this.projection = envelopeProjection;
|
60 |
this.builder = builder;
|
61 |
this.geomName = geomName;
|
62 |
this.getFieldsInfo().addMatchFieldValue(geomName, envelope);
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
67 |
Envelope featureEnvelope; |
68 |
Geometry geom ; |
69 |
if (isDefault) {
|
70 |
geom = (Geometry) data.getDataValue(defaultGeometryAttributeName); |
71 |
featureEnvelope = ((Feature) data.getContextValue("feature")).getDefaultEnvelope();
|
72 |
} else {
|
73 |
geom = (Geometry) data.getDataValue(geomName); |
74 |
if (geom == null) { |
75 |
return false; |
76 |
} |
77 |
featureEnvelope = geom.getEnvelope(); |
78 |
} |
79 |
if (envelope.intersects(featureEnvelope)) {
|
80 |
return envelope.intersects(geom);
|
81 |
} |
82 |
return false; |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public String getName() { |
87 |
return "intersects envelope"; |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public String getSQL() { |
92 |
ExpressionBuilder.Variable column = builder.column(fad.getName()); |
93 |
IProjection theProjection = this.projection;
|
94 |
if( this.fad.getSRS()==null ) { |
95 |
theProjection = null;
|
96 |
} |
97 |
return builder.set(
|
98 |
builder.and( |
99 |
builder.not_is_null(column) , |
100 |
builder.ST_Intersects( |
101 |
column, |
102 |
builder.geometry(envelope.getGeometry(), theProjection) |
103 |
) |
104 |
) |
105 |
).toString(); |
106 |
} |
107 |
} |