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 / ContainsEnvelopeEvaluator.java @ 44644
History | View | Annotate | Download (3.51 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 43040 | 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 | 43040 | 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 | 43040 | 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 | 43040 | 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 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
28 | 40435 | jjdelcerro | |
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 ContainsEnvelopeEvaluator extends AbstractEvaluator { |
||
39 | |||
40 | 43040 | jjdelcerro | private final Envelope envelope; |
41 | private final String geomName; |
||
42 | private final Envelope envelopeTrans; |
||
43 | private final boolean isDefault; |
||
44 | 44644 | jjdelcerro | private final GeometryExpressionBuilder builder; |
45 | 43040 | jjdelcerro | private final IProjection projection; |
46 | 43739 | jjdelcerro | private final FeatureAttributeDescriptor fad; |
47 | 44043 | jjdelcerro | |
48 | 43040 | jjdelcerro | ContainsEnvelopeEvaluator( |
49 | Envelope envelope, |
||
50 | IProjection envelopeProjection, |
||
51 | FeatureType featureType, |
||
52 | String geomName,
|
||
53 | 44644 | jjdelcerro | GeometryExpressionBuilder builder |
54 | 43040 | jjdelcerro | ) { |
55 | 43739 | jjdelcerro | fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
56 | 43040 | jjdelcerro | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
|
57 | this.projection = envelopeProjection;
|
||
58 | this.builder = builder;
|
||
59 | this.envelope = envelope;
|
||
60 | this.envelopeTrans = envelope;
|
||
61 | this.geomName = geomName;
|
||
62 | this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
|
||
63 | } |
||
64 | 40435 | jjdelcerro | |
65 | 43040 | jjdelcerro | @Override
|
66 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
67 | Envelope featureEnvelope; |
||
68 | if (isDefault) {
|
||
69 | featureEnvelope = ((Feature) data.getContextValue("feature"))
|
||
70 | .getDefaultEnvelope(); |
||
71 | 40435 | jjdelcerro | |
72 | 43040 | jjdelcerro | } else {
|
73 | Geometry geom = (Geometry) data.getDataValue(geomName); |
||
74 | if (geom == null) { |
||
75 | return false; |
||
76 | } |
||
77 | featureEnvelope = geom.getEnvelope(); |
||
78 | } |
||
79 | return envelopeTrans.contains(featureEnvelope);
|
||
80 | } |
||
81 | 40435 | jjdelcerro | |
82 | 43040 | jjdelcerro | @Override
|
83 | public String getName() { |
||
84 | return "contains in envelope"; |
||
85 | } |
||
86 | 40435 | jjdelcerro | |
87 | 43040 | jjdelcerro | @Override
|
88 | public String getSQL() { |
||
89 | return this.builder.set( |
||
90 | builder.ST_Contains( |
||
91 | builder.envelope(envelope, projection), |
||
92 | 44043 | jjdelcerro | builder.column(fad.getName()) |
93 | 43040 | jjdelcerro | ) |
94 | ).toString(); |
||
95 | } |
||
96 | 40435 | jjdelcerro | |
97 | } |