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 / TouchesGeometryEvaluator.java @ 43739

History | View | Annotate | Download (4.34 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 43034 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
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 TouchesGeometryEvaluator 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
    private final ExpressionBuilder builder;
43
    private final IProjection projection;
44 43739 jjdelcerro
    private final FeatureAttributeDescriptor fad;
45 40435 jjdelcerro
46 43040 jjdelcerro
    /**
47
     * @param geometry
48
     * @param projection
49
     * @param featureType
50
     * @param geomName
51
     * @deprecated  use @{link org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory}
52
     */
53
    public TouchesGeometryEvaluator(Geometry geometry,
54
            IProjection projection,
55
            FeatureType featureType,
56
            String geomName
57
    ) {
58
        this(
59
                geometry,
60
                projection,
61
                featureType,
62
                geomName,
63
                SpatialEvaluatorsFactory.getInstance().createBuilder()
64
        );
65
    }
66
67 43034 jjdelcerro
    TouchesGeometryEvaluator(Geometry geometry,
68
            IProjection projection,
69
            FeatureType featureType,
70
            String geomName,
71
            ExpressionBuilder builder
72
        ) {
73 43739 jjdelcerro
        fad = (FeatureAttributeDescriptor) featureType.get(geomName);
74
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
75 43034 jjdelcerro
        this.geometry = geometry;
76
        this.geometryTrans = geometry.cloneGeometry();
77
        this.projection = projection;
78
        this.builder = builder;
79 40435 jjdelcerro
80 43034 jjdelcerro
        IProjection fad_proj = fad.getSRS();
81
        ICoordTrans ct = null;
82 40435 jjdelcerro
83 43034 jjdelcerro
        if (fad_proj != null && !fad_proj.equals(projection)) {
84
            ct = projection.getCT(fad_proj);
85
        }
86 40435 jjdelcerro
87 43034 jjdelcerro
        if (ct != null) {
88
            geometryTrans.reProject(ct);
89
        }
90
        this.geomName = geomName;
91 40435 jjdelcerro
92 43034 jjdelcerro
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
93 40435 jjdelcerro
94 43034 jjdelcerro
    }
95 40435 jjdelcerro
96 43034 jjdelcerro
    @Override
97
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
98
        try {
99
            Geometry geom;
100
            if (isDefault) {
101
                Feature feature = (Feature) data.getContextValue("feature");
102
                geom = feature.getDefaultGeometry();
103 40435 jjdelcerro
104 43034 jjdelcerro
            } else {
105
                geom = (Geometry) data.getDataValue(geomName);
106
            }
107
            if (geom == null) {
108
                return Boolean.FALSE;
109
            }
110
            return geometryTrans.touches(geom);
111 40435 jjdelcerro
112 43034 jjdelcerro
        } catch (Exception e) {
113
            throw new EvaluatorException(e);
114
        }
115
    }
116
117
    @Override
118
    public String getName() {
119
        return "touches with geometry";
120
    }
121
122
    @Override
123
    public String getSQL() {
124
        return this.builder.set(
125
                builder.ST_Touches(
126
                        builder.geometry(geometry, projection),
127 43739 jjdelcerro
                        builder.column(fad)
128 43034 jjdelcerro
                )
129
        ).toString();
130
    }
131 40435 jjdelcerro
}