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 @ 43739
History | View | Annotate | Download (4.45 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 | 43040 | jjdelcerro | private final Envelope envelope; |
40 | private final String geomName; |
||
41 | private final boolean isDefault; |
||
42 | private final String defaultGeometryAttributeName; |
||
43 | private final IProjection projection; |
||
44 | private final ExpressionBuilder builder; |
||
45 | 43739 | jjdelcerro | FeatureAttributeDescriptor fad; |
46 | 43020 | jjdelcerro | |
47 | 43040 | jjdelcerro | /**
|
48 | * @param envelope
|
||
49 | * @param envelopeProjection
|
||
50 | * @param featureType
|
||
51 | * @param geomName
|
||
52 | * @deprecated use @{link org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory}
|
||
53 | */
|
||
54 | public IntersectsEnvelopeEvaluator(
|
||
55 | Envelope envelope, |
||
56 | IProjection envelopeProjection, |
||
57 | FeatureType featureType, |
||
58 | String geomName
|
||
59 | ) { |
||
60 | this(
|
||
61 | envelope, |
||
62 | envelopeProjection, |
||
63 | featureType, |
||
64 | geomName, |
||
65 | SpatialEvaluatorsFactory.getInstance().createBuilder() |
||
66 | ); |
||
67 | } |
||
68 | |||
69 | IntersectsEnvelopeEvaluator( |
||
70 | Envelope envelope, |
||
71 | IProjection envelopeProjection, |
||
72 | FeatureType featureType, |
||
73 | 43020 | jjdelcerro | String geomName,
|
74 | 43040 | jjdelcerro | ExpressionBuilder builder |
75 | ) { |
||
76 | 43739 | jjdelcerro | fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
77 | 43020 | jjdelcerro | defaultGeometryAttributeName = featureType.getDefaultGeometryAttributeName(); |
78 | this.isDefault = defaultGeometryAttributeName.equals(geomName);
|
||
79 | this.envelope = envelope;
|
||
80 | 43040 | jjdelcerro | this.projection = envelopeProjection;
|
81 | this.builder = builder;
|
||
82 | 43020 | jjdelcerro | this.geomName = geomName;
|
83 | this.getFieldsInfo().addMatchFieldValue(geomName, envelope);
|
||
84 | } |
||
85 | 40435 | jjdelcerro | |
86 | 43020 | jjdelcerro | @Override
|
87 | 42464 | fdiaz | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
88 | Envelope featureEnvelope; |
||
89 | 43020 | jjdelcerro | Geometry geom ; |
90 | 42464 | fdiaz | if (isDefault) {
|
91 | geom = (Geometry) data.getDataValue(defaultGeometryAttributeName); |
||
92 | featureEnvelope = ((Feature) data.getContextValue("feature")).getDefaultEnvelope();
|
||
93 | } else {
|
||
94 | geom = (Geometry) data.getDataValue(geomName); |
||
95 | if (geom == null) { |
||
96 | 43040 | jjdelcerro | return false; |
97 | 42464 | fdiaz | } |
98 | featureEnvelope = geom.getEnvelope(); |
||
99 | } |
||
100 | 43020 | jjdelcerro | if (envelope.intersects(featureEnvelope)) {
|
101 | return envelope.intersects(geom);
|
||
102 | 42464 | fdiaz | } |
103 | 43040 | jjdelcerro | return false; |
104 | 42464 | fdiaz | } |
105 | 40435 | jjdelcerro | |
106 | 43020 | jjdelcerro | @Override
|
107 | public String getName() { |
||
108 | return "intersects envelope"; |
||
109 | } |
||
110 | 40435 | jjdelcerro | |
111 | 43020 | jjdelcerro | @Override
|
112 | public String getSQL() { |
||
113 | 43355 | jjdelcerro | // Los gestores de BBDD no usan indices si se envuelve la columna
|
114 | // geometria con la funcion ST_envelope.
|
||
115 | |||
116 | 43040 | jjdelcerro | return builder.set(
|
117 | builder.ST_Intersects( |
||
118 | builder.geometry(envelope.getGeometry(), this.projection),
|
||
119 | 43355 | jjdelcerro | // builder.ST_Envelope(builder.column(geomName))
|
120 | 43739 | jjdelcerro | builder.column(fad) |
121 | 43040 | jjdelcerro | ) |
122 | ).toString(); |
||
123 | 43020 | jjdelcerro | } |
124 | 40435 | jjdelcerro | } |