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 / OutGeometryEvaluator.java @ 41348
History | View | Annotate | Download (3.26 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.fmap.mapcontext.layers.vectorial; |
25 | |||
26 | import org.cresques.cts.ICoordTrans; |
||
27 | import org.cresques.cts.IProjection; |
||
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.tools.evaluator.AbstractEvaluator; |
||
33 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
34 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
35 | /**
|
||
36 | *
|
||
37 | * @author Vicente Caballero Navarro
|
||
38 | *
|
||
39 | */
|
||
40 | public class OutGeometryEvaluator extends AbstractEvaluator { |
||
41 | |||
42 | private String geomName; |
||
43 | private Geometry geometry;
|
||
44 | private Geometry geometryTrans;
|
||
45 | private String srs; |
||
46 | private boolean isDefault; |
||
47 | |||
48 | public OutGeometryEvaluator(Geometry geometry,
|
||
49 | IProjection envelopeProjection, FeatureType featureType, |
||
50 | String geomName) {
|
||
51 | FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType |
||
52 | .get(geomName); |
||
53 | this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
|
||
54 | geomName); |
||
55 | this.geometry = geometry;
|
||
56 | this.geometryTrans = geometry.cloneGeometry();
|
||
57 | this.srs = envelopeProjection.getAbrev();
|
||
58 | |||
59 | IProjection fad_proj = fad.getSRS(); |
||
60 | ICoordTrans ct = null;
|
||
61 | |||
62 | if (fad_proj != null && !fad_proj.equals(envelopeProjection)) { |
||
63 | ct = envelopeProjection.getCT(fad_proj); |
||
64 | } |
||
65 | |||
66 | if (ct != null) { |
||
67 | geometryTrans.reProject(ct); |
||
68 | } |
||
69 | this.geomName = geomName;
|
||
70 | |||
71 | this.getFieldsInfo().addFieldValue(geomName);
|
||
72 | |||
73 | } |
||
74 | |||
75 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
76 | try {
|
||
77 | Geometry geom = null;
|
||
78 | if (isDefault) {
|
||
79 | Feature feature = (Feature) data.getContextValue("feature");
|
||
80 | geom = feature.getDefaultGeometry(); |
||
81 | |||
82 | } else {
|
||
83 | geom = (Geometry) data.getDataValue(geomName); |
||
84 | } |
||
85 | 41348 | jjdelcerro | if ( geom == null ) { |
86 | return Boolean.FALSE; |
||
87 | } |
||
88 | 40435 | jjdelcerro | return new Boolean(!geometryTrans.contains(geom) && !geometryTrans.intersects(geom)); |
89 | |||
90 | } catch (Exception e) { |
||
91 | throw new EvaluatorException(e); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | public String getName() { |
||
96 | return "out of geometry"; |
||
97 | } |
||
98 | |||
99 | public String getSQL() { |
||
100 | return " not ST_contains(ST_GeomFromText('" + geometry.toString() + "', " + "'" |
||
101 | + srs + "'" + "), " + geomName + ") "; |
||
102 | } |
||
103 | |||
104 | } |