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 / EqualsGeometryEvaluator.java @ 45426
History | View | Annotate | Download (3.78 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.ICoordTrans; |
||
26 | import org.cresques.cts.IProjection; |
||
27 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
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.tools.evaluator.AbstractEvaluator; |
||
33 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
34 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
35 | 43034 | jjdelcerro | |
36 | 40435 | jjdelcerro | public class EqualsGeometryEvaluator extends AbstractEvaluator { |
37 | |||
38 | 43034 | jjdelcerro | private final String geomName; |
39 | private final Geometry geometry; |
||
40 | private final Geometry geometryTrans; |
||
41 | private final boolean isDefault; |
||
42 | 44644 | jjdelcerro | private final GeometryExpressionBuilder builder; |
43 | 43034 | jjdelcerro | private final IProjection projection; |
44 | 43739 | jjdelcerro | private final FeatureAttributeDescriptor fad; |
45 | 40435 | jjdelcerro | |
46 | 43034 | jjdelcerro | EqualsGeometryEvaluator( |
47 | Geometry geometry, |
||
48 | IProjection projection, |
||
49 | FeatureType featureType, |
||
50 | String geomName,
|
||
51 | 44644 | jjdelcerro | GeometryExpressionBuilder builder |
52 | 43034 | jjdelcerro | ) { |
53 | this.builder = builder;
|
||
54 | this.projection = projection;
|
||
55 | 43739 | jjdelcerro | fad = (FeatureAttributeDescriptor) featureType.get(geomName); |
56 | 43034 | jjdelcerro | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
|
57 | this.geometry = geometry;
|
||
58 | this.geometryTrans = geometry.cloneGeometry();
|
||
59 | 40435 | jjdelcerro | |
60 | 43034 | jjdelcerro | IProjection fad_proj = fad.getSRS(); |
61 | ICoordTrans ct = null;
|
||
62 | 40435 | jjdelcerro | |
63 | 43034 | jjdelcerro | if (fad_proj != null && !fad_proj.equals(projection)) { |
64 | ct = projection.getCT(fad_proj); |
||
65 | } |
||
66 | 40435 | jjdelcerro | |
67 | 43034 | jjdelcerro | if (ct != null) { |
68 | geometryTrans.reProject(ct); |
||
69 | } |
||
70 | this.geomName = geomName;
|
||
71 | 40435 | jjdelcerro | |
72 | 43034 | jjdelcerro | this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
|
73 | 40435 | jjdelcerro | |
74 | 43034 | jjdelcerro | } |
75 | 40435 | jjdelcerro | |
76 | 43034 | jjdelcerro | @Override
|
77 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
78 | try {
|
||
79 | Geometry geom; |
||
80 | if (isDefault) {
|
||
81 | Feature feature = (Feature) data.getContextValue("feature");
|
||
82 | geom = feature.getDefaultGeometry(); |
||
83 | 40435 | jjdelcerro | |
84 | 43034 | jjdelcerro | } else {
|
85 | geom = (Geometry) data.getDataValue(geomName); |
||
86 | } |
||
87 | if (geom == null) { |
||
88 | return Boolean.FALSE; |
||
89 | } |
||
90 | return geometryTrans.equals(geom);
|
||
91 | 40435 | jjdelcerro | |
92 | 43034 | jjdelcerro | } catch (Exception e) { |
93 | throw new EvaluatorException(e); |
||
94 | } |
||
95 | } |
||
96 | 40435 | jjdelcerro | |
97 | 43034 | jjdelcerro | @Override
|
98 | public String getName() { |
||
99 | return "equals with geometry"; |
||
100 | } |
||
101 | |||
102 | @Override
|
||
103 | public String getSQL() { |
||
104 | return this.builder.set( |
||
105 | builder.ST_Equals( |
||
106 | builder.geometry(geometry, projection), |
||
107 | 44043 | jjdelcerro | builder.column(fad.getName()) |
108 | 43034 | jjdelcerro | ) |
109 | ).toString(); |
||
110 | } |
||
111 | |||
112 | 40435 | jjdelcerro | } |