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 / IntersectsGeometryEvaluator.java @ 43020
History | View | Annotate | Download (3.63 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.ICoordTrans; |
||
26 | import org.cresques.cts.IProjection; |
||
27 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.ExpressionBuilder; |
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 | 43020 | jjdelcerro | import org.gvsig.fmap.dal.SQLBuilder; |
32 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
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 IntersectsGeometryEvaluator extends AbstractEvaluator { |
||
38 | |||
39 | 43020 | jjdelcerro | private String geomName; |
40 | private Geometry geometry;
|
||
41 | private Geometry geometryTrans;
|
||
42 | private boolean isDefault; |
||
43 | private ExpressionBuilder condition;
|
||
44 | 40435 | jjdelcerro | |
45 | 43020 | jjdelcerro | IntersectsGeometryEvaluator(Geometry geometry, |
46 | IProjection projection, FeatureType featureType, |
||
47 | String geomName,
|
||
48 | ExpressionBuilder builder) { |
||
49 | FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
||
50 | .get(geomName); |
||
51 | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
|
||
52 | this.geometry = geometry;
|
||
53 | this.geometryTrans = geometry.cloneGeometry();
|
||
54 | ICoordTrans ct = null;
|
||
55 | 40435 | jjdelcerro | |
56 | 43020 | jjdelcerro | IProjection ipro = fad.getSRS(); |
57 | if (ipro != null && !ipro.equals(projection)) { |
||
58 | ct = projection.getCT(ipro); |
||
59 | } |
||
60 | 40435 | jjdelcerro | |
61 | 43020 | jjdelcerro | if (ct != null) { |
62 | geometryTrans.reProject(ct); |
||
63 | } |
||
64 | this.geomName = geomName;
|
||
65 | this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
||
66 | this.condition = builder.set(
|
||
67 | builder.ST_Intersects( |
||
68 | builder.geometry(geometry, projection), |
||
69 | builder.column(geomName) |
||
70 | ) |
||
71 | ); |
||
72 | } |
||
73 | 40435 | jjdelcerro | |
74 | 43020 | jjdelcerro | @Override
|
75 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
76 | try {
|
||
77 | Geometry geom ; |
||
78 | if (isDefault) {
|
||
79 | Feature feature = (Feature) data.getContextValue("feature");
|
||
80 | geom = feature.getDefaultGeometry(); |
||
81 | 40435 | jjdelcerro | |
82 | 43020 | jjdelcerro | } else {
|
83 | geom = (Geometry) data.getDataValue(geomName); |
||
84 | } |
||
85 | if (geom == null) { |
||
86 | return Boolean.FALSE; |
||
87 | } |
||
88 | return geometryTrans.intersects(geom);
|
||
89 | 40435 | jjdelcerro | |
90 | 43020 | jjdelcerro | } catch (Exception e) { |
91 | return Boolean.FALSE; |
||
92 | } |
||
93 | } |
||
94 | 40435 | jjdelcerro | |
95 | 43020 | jjdelcerro | @Override
|
96 | public String getName() { |
||
97 | return "intersects with geometry"; |
||
98 | } |
||
99 | 40435 | jjdelcerro | |
100 | 43020 | jjdelcerro | @Override
|
101 | public String getSQL() { |
||
102 | return this.condition.toString(); |
||
103 | } |
||
104 | 40435 | jjdelcerro | |
105 | } |