Statistics
| Revision:

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 / DisjointGeometryEvaluator.java @ 40559

History | View | Annotate | Download (3.63 KB)

1
/**
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
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.exception.DataEvaluatorRuntimeException;
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.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.tools.evaluator.AbstractEvaluator;
36
import org.gvsig.tools.evaluator.EvaluatorData;
37
import org.gvsig.tools.evaluator.EvaluatorException;
38
/**
39
 *
40
 * @author Vicente Caballero Navarro
41
 *
42
 */
43
public class DisjointGeometryEvaluator extends AbstractEvaluator {
44

    
45
        private String geomName;
46
        private Geometry geometry;
47
        private Geometry geometryTrans;
48
        private String srs;
49
        private boolean isDefault;
50
        private String geometryWKT;
51

    
52
        public DisjointGeometryEvaluator(Geometry geometry,
53
                        IProjection projection,
54
                        FeatureType featureType,
55
                        String geomName) {
56
                FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
57
                                .get(geomName);
58
                this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
59
                                geomName);
60
                this.geometry = geometry;
61
                this.geometryTrans = geometry.cloneGeometry();
62
                this.srs = projection.getAbrev();
63
                
64
                IProjection fad_proj = fad.getSRS();
65
                ICoordTrans ct = null;
66
                
67
                if (fad_proj != null && !fad_proj.equals(projection)) {
68
                    ct = projection.getCT(fad_proj);
69
                }
70

    
71
                if (ct != null) {
72
                        geometryTrans.reProject(ct);
73
                }
74
                this.geomName = geomName;
75

    
76
                this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
77

    
78
        }
79

    
80
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
81
                try {
82
                        Geometry geom = null;
83
                        if (isDefault) {
84
                                Feature feature = (Feature) data.getContextValue("feature");
85
                                geom = feature.getDefaultGeometry();
86

    
87
                        } else {
88
                                geom = (Geometry) data.getDataValue(geomName);
89
                        }
90
                        return new Boolean(geometryTrans.disjoint(geom));
91

    
92
                } catch (Exception e) {
93
                        throw new EvaluatorException(e);
94
                }
95
        }
96

    
97
        public String getName() {
98
                return "disjoint with geometry";
99
        }
100

    
101
        public String getSQL() {
102
                if (geometryWKT == null) {
103
                        try {
104
                                geometryWKT = geometry.convertToWKT();
105
                        } catch (GeometryOperationNotSupportedException e) {
106
                                throw new DataEvaluatorRuntimeException(e);
107
                        } catch (GeometryOperationException e) {
108
                                throw new DataEvaluatorRuntimeException(e);
109
                        }
110
                }
111
                return " ST_disjoint(ST_GeomFromText('" + geometryWKT + "', " + "'"
112
                                + srs + "'" + "), " + geomName + ") ";
113
        }
114

    
115
}