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 @ 43020
History | View | Annotate | Download (3.49 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 43020 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
11 | 43020 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 43020 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
20 | 43020 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40559 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.fmap.mapcontext.layers.vectorial; |
24 | |||
25 | import org.cresques.cts.IProjection; |
||
26 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.ExpressionBuilder; |
27 | 42464 | fdiaz | |
28 | 40435 | jjdelcerro | 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 IntersectsEnvelopeEvaluator extends AbstractEvaluator { |
||
38 | |||
39 | 43020 | jjdelcerro | private Envelope envelope;
|
40 | private String geomName; |
||
41 | private boolean isDefault; |
||
42 | private ExpressionBuilder condition;
|
||
43 | String defaultGeometryAttributeName;
|
||
44 | |||
45 | 40435 | jjdelcerro | |
46 | 43020 | jjdelcerro | IntersectsEnvelopeEvaluator(Envelope envelope, |
47 | IProjection envelopeProjection, FeatureType featureType, |
||
48 | String geomName,
|
||
49 | ExpressionBuilder builder) { |
||
50 | FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
||
51 | defaultGeometryAttributeName = featureType.getDefaultGeometryAttributeName(); |
||
52 | this.isDefault = defaultGeometryAttributeName.equals(geomName);
|
||
53 | this.envelope = envelope;
|
||
54 | this.geomName = geomName;
|
||
55 | this.getFieldsInfo().addMatchFieldValue(geomName, envelope);
|
||
56 | 40435 | jjdelcerro | |
57 | 43020 | jjdelcerro | this.condition = builder.set(
|
58 | builder.ST_Intersects( |
||
59 | builder.geometry(envelope.getGeometry(), envelopeProjection), |
||
60 | builder.ST_Envelope(builder.column(geomName)) |
||
61 | ) |
||
62 | ); |
||
63 | } |
||
64 | 40435 | jjdelcerro | |
65 | 43020 | jjdelcerro | @Override
|
66 | 42464 | fdiaz | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
67 | Envelope featureEnvelope; |
||
68 | 43020 | jjdelcerro | Geometry geom ; |
69 | 42464 | fdiaz | 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 Boolean.FALSE; |
||
76 | } |
||
77 | featureEnvelope = geom.getEnvelope(); |
||
78 | } |
||
79 | 43020 | jjdelcerro | if (envelope.intersects(featureEnvelope)) {
|
80 | return envelope.intersects(geom);
|
||
81 | 42464 | fdiaz | } |
82 | return Boolean.FALSE; |
||
83 | } |
||
84 | 40435 | jjdelcerro | |
85 | 43020 | jjdelcerro | @Override
|
86 | public String getName() { |
||
87 | return "intersects envelope"; |
||
88 | } |
||
89 | 40435 | jjdelcerro | |
90 | 43020 | jjdelcerro | @Override
|
91 | public String getSQL() { |
||
92 | return this.condition.toString(); |
||
93 | } |
||
94 | 40435 | jjdelcerro | } |