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

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