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 @ 43739
History | View | Annotate | Download (4.62 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 43034 | 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 | 43034 | 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 | 43034 | 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 | 43034 | 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 | 43034 | jjdelcerro | import org.gvsig.fmap.dal.ExpressionBuilder; |
27 | 40435 | jjdelcerro | |
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 | 43034 | jjdelcerro | 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 | 43739 | jjdelcerro | private final FeatureAttributeDescriptor fad; |
46 | 40435 | 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 CrossEnvelopeEvaluator(
|
||
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 | 43034 | jjdelcerro | CrossEnvelopeEvaluator( |
70 | Envelope envelope, |
||
71 | IProjection envelopeProjection, |
||
72 | FeatureType featureType, |
||
73 | String geomName,
|
||
74 | ExpressionBuilder builder |
||
75 | ) { |
||
76 | 43739 | jjdelcerro | fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
77 | 40435 | jjdelcerro | |
78 | 43034 | jjdelcerro | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
|
79 | this.envelope = envelope;
|
||
80 | this.projection = envelopeProjection;
|
||
81 | this.builder = builder;
|
||
82 | // this.srs = envelopeProjection.getAbrev();
|
||
83 | // this.projection=CRSFactory.getCRS(fad.getSRS());
|
||
84 | // this.envelopeProjection=envelopeProjection;
|
||
85 | 40435 | jjdelcerro | // ICoordTrans ct = null;
|
86 | // if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n
|
||
87 | // ct = envelopeProjection.getCT(fad.getSRS());
|
||
88 | // }
|
||
89 | // if (ct != null) {
|
||
90 | // this.envelopeTrans = envelope.convert(ct);
|
||
91 | // } else {
|
||
92 | 43034 | jjdelcerro | this.envelopeTrans = envelope;
|
93 | 40435 | jjdelcerro | // }
|
94 | 43034 | jjdelcerro | this.geomName = geomName;
|
95 | 40435 | jjdelcerro | |
96 | 43034 | jjdelcerro | this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
97 | 40435 | jjdelcerro | |
98 | 43034 | jjdelcerro | } |
99 | 40435 | jjdelcerro | |
100 | 43034 | jjdelcerro | @Override
|
101 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
102 | if (isDefault) {
|
||
103 | Feature feature = (Feature) data.getContextValue("feature");
|
||
104 | Envelope featureEnvelope = feature.getDefaultEnvelope(); |
||
105 | if (featureEnvelope == null) { |
||
106 | return Boolean.FALSE; |
||
107 | } |
||
108 | Boolean r = envelopeTrans.intersects(featureEnvelope);
|
||
109 | return r;
|
||
110 | 40435 | jjdelcerro | |
111 | 43034 | jjdelcerro | } else {
|
112 | Geometry geom = (Geometry) data.getDataValue(geomName); |
||
113 | if (geom == null) { |
||
114 | return Boolean.FALSE; |
||
115 | } |
||
116 | return envelopeTrans.intersects(geom.getEnvelope());
|
||
117 | 40435 | jjdelcerro | |
118 | 43034 | jjdelcerro | } |
119 | } |
||
120 | 40435 | jjdelcerro | |
121 | 43034 | jjdelcerro | @Override
|
122 | public String getName() { |
||
123 | return "contains in envelope"; |
||
124 | } |
||
125 | 40435 | jjdelcerro | |
126 | 43034 | jjdelcerro | @Override
|
127 | public String getSQL() { |
||
128 | return this.builder.set( |
||
129 | builder.ST_Intersects( |
||
130 | builder.envelope(envelope, projection), |
||
131 | 43739 | jjdelcerro | builder.ST_Envelope(builder.column(fad)) |
132 | 43034 | jjdelcerro | ) |
133 | ).toString(); |
||
134 | } |
||
135 | 40435 | jjdelcerro | } |