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 @ 44043
History | View | Annotate | Download (3.6 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 | 44043 | jjdelcerro | import org.gvsig.expressionevaluator.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 | 43040 | jjdelcerro | |
47 | 43034 | jjdelcerro | CrossEnvelopeEvaluator( |
48 | Envelope envelope, |
||
49 | IProjection envelopeProjection, |
||
50 | FeatureType featureType, |
||
51 | String geomName,
|
||
52 | ExpressionBuilder builder |
||
53 | ) { |
||
54 | 43739 | jjdelcerro | fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
55 | 40435 | jjdelcerro | |
56 | 43034 | jjdelcerro | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
|
57 | this.envelope = envelope;
|
||
58 | this.projection = envelopeProjection;
|
||
59 | this.builder = builder;
|
||
60 | this.envelopeTrans = envelope;
|
||
61 | this.geomName = geomName;
|
||
62 | 40435 | jjdelcerro | |
63 | 43034 | jjdelcerro | this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
64 | } |
||
65 | 40435 | jjdelcerro | |
66 | 43034 | jjdelcerro | @Override
|
67 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
68 | if (isDefault) {
|
||
69 | Feature feature = (Feature) data.getContextValue("feature");
|
||
70 | Envelope featureEnvelope = feature.getDefaultEnvelope(); |
||
71 | if (featureEnvelope == null) { |
||
72 | return Boolean.FALSE; |
||
73 | } |
||
74 | Boolean r = envelopeTrans.intersects(featureEnvelope);
|
||
75 | return r;
|
||
76 | 40435 | jjdelcerro | |
77 | 43034 | jjdelcerro | } else {
|
78 | Geometry geom = (Geometry) data.getDataValue(geomName); |
||
79 | if (geom == null) { |
||
80 | return Boolean.FALSE; |
||
81 | } |
||
82 | return envelopeTrans.intersects(geom.getEnvelope());
|
||
83 | 40435 | jjdelcerro | |
84 | 43034 | jjdelcerro | } |
85 | } |
||
86 | 40435 | jjdelcerro | |
87 | 43034 | jjdelcerro | @Override
|
88 | public String getName() { |
||
89 | return "contains in envelope"; |
||
90 | } |
||
91 | 40435 | jjdelcerro | |
92 | 43034 | jjdelcerro | @Override
|
93 | public String getSQL() { |
||
94 | return this.builder.set( |
||
95 | builder.ST_Intersects( |
||
96 | builder.envelope(envelope, projection), |
||
97 | 44043 | jjdelcerro | builder.ST_Envelope(builder.column(fad.getName())) |
98 | 43034 | jjdelcerro | ) |
99 | ).toString(); |
||
100 | } |
||
101 | 40435 | jjdelcerro | } |