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 / IntersectsGeometryEvaluator.java @ 44644

History | View | Annotate | Download (4.02 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 43020 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 43020 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 43020 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 43020 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 44043 jjdelcerro
import org.gvsig.expressionevaluator.ExpressionBuilder;
28 44644 jjdelcerro
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
29 40435 jjdelcerro
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.tools.evaluator.AbstractEvaluator;
34
import org.gvsig.tools.evaluator.EvaluatorData;
35
import org.gvsig.tools.evaluator.EvaluatorException;
36
37
public class IntersectsGeometryEvaluator extends AbstractEvaluator {
38
39 43040 jjdelcerro
    private final String geomName;
40
    private final Geometry geometry;
41
    private final Geometry geometryTrans;
42
    private final boolean isDefault;
43 44644 jjdelcerro
    private final GeometryExpressionBuilder builder;
44 43040 jjdelcerro
    private final IProjection projection;
45 43739 jjdelcerro
    private final FeatureAttributeDescriptor fad;
46 44043 jjdelcerro
47 43040 jjdelcerro
    IntersectsGeometryEvaluator(
48
            Geometry geometry,
49
            IProjection projection,
50
            FeatureType featureType,
51 43020 jjdelcerro
            String geomName,
52 44644 jjdelcerro
            GeometryExpressionBuilder builder
53 43040 jjdelcerro
        ) {
54 43739 jjdelcerro
        fad = (FeatureAttributeDescriptor) featureType
55 43020 jjdelcerro
                .get(geomName);
56
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
57
        this.geometry = geometry;
58 43040 jjdelcerro
        this.projection = projection;
59
        this.builder = builder;
60 43020 jjdelcerro
        this.geometryTrans = geometry.cloneGeometry();
61
        ICoordTrans ct = null;
62 40435 jjdelcerro
63 43020 jjdelcerro
        IProjection ipro = fad.getSRS();
64
        if (ipro != null && !ipro.equals(projection)) {
65
            ct = projection.getCT(ipro);
66
        }
67 40435 jjdelcerro
68 43020 jjdelcerro
        if (ct != null) {
69
            geometryTrans.reProject(ct);
70
        }
71
        this.geomName = geomName;
72
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
73
    }
74 40435 jjdelcerro
75 43020 jjdelcerro
    @Override
76
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
77
        try {
78 43040 jjdelcerro
            Geometry geom;
79 43020 jjdelcerro
            if (isDefault) {
80
                Feature feature = (Feature) data.getContextValue("feature");
81
                geom = feature.getDefaultGeometry();
82 40435 jjdelcerro
83 43020 jjdelcerro
            } else {
84
                geom = (Geometry) data.getDataValue(geomName);
85
            }
86
            if (geom == null) {
87
                return Boolean.FALSE;
88
            }
89
            return geometryTrans.intersects(geom);
90 40435 jjdelcerro
91 43020 jjdelcerro
        } catch (Exception e) {
92
            return Boolean.FALSE;
93
        }
94
    }
95 40435 jjdelcerro
96 43020 jjdelcerro
    @Override
97
    public String getName() {
98
        return "intersects with geometry";
99
    }
100 40435 jjdelcerro
101 43020 jjdelcerro
    @Override
102
    public String getSQL() {
103 44361 jjdelcerro
        ExpressionBuilder.Variable column = builder.column(fad.getName());
104 43040 jjdelcerro
        return builder.set(
105 44361 jjdelcerro
                builder.and(
106
                    builder.not_is_null(column),
107
                    builder.ST_Intersects(
108
                            column,
109
                            builder.geometry(geometry, this.projection)
110
                    )
111 43040 jjdelcerro
                )
112
        ).toString();
113 43020 jjdelcerro
    }
114 40435 jjdelcerro
115
}