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 @ 44644

History | View | Annotate | Download (3.78 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 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
 *
11
 * 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
 *
16
 * 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
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontext.layers.vectorial;
24

    
25
import org.cresques.cts.ICoordTrans;
26
import org.cresques.cts.IProjection;
27
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
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
public class TouchesGeometryEvaluator extends AbstractEvaluator {
37

    
38
    private final String geomName;
39
    private final Geometry geometry;
40
    private final Geometry geometryTrans;
41
    private final boolean isDefault;
42
    private final GeometryExpressionBuilder builder;
43
    private final IProjection projection;
44
    private final FeatureAttributeDescriptor fad;
45
    
46
    TouchesGeometryEvaluator(Geometry geometry,
47
            IProjection projection,
48
            FeatureType featureType,
49
            String geomName,
50
            GeometryExpressionBuilder builder
51
        ) {
52
        fad = (FeatureAttributeDescriptor) featureType.get(geomName);
53
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
54
        this.geometry = geometry;
55
        this.geometryTrans = geometry.cloneGeometry();
56
        this.projection = projection;
57
        this.builder = builder;
58

    
59
        IProjection fad_proj = fad.getSRS();
60
        ICoordTrans ct = null;
61

    
62
        if (fad_proj != null && !fad_proj.equals(projection)) {
63
            ct = projection.getCT(fad_proj);
64
        }
65

    
66
        if (ct != null) {
67
            geometryTrans.reProject(ct);
68
        }
69
        this.geomName = geomName;
70

    
71
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
72

    
73
    }
74

    
75
    @Override
76
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
77
        try {
78
            Geometry geom;
79
            if (isDefault) {
80
                Feature feature = (Feature) data.getContextValue("feature");
81
                geom = feature.getDefaultGeometry();
82

    
83
            } else {
84
                geom = (Geometry) data.getDataValue(geomName);
85
            }
86
            if (geom == null) {
87
                return Boolean.FALSE;
88
            }
89
            return geometryTrans.touches(geom);
90

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

    
96
    @Override
97
    public String getName() {
98
        return "touches with geometry";
99
    }
100

    
101
    @Override
102
    public String getSQL() {
103
        return this.builder.set(
104
                builder.ST_Touches(
105
                        builder.geometry(geometry, projection),
106
                        builder.column(fad.getName())
107
                )
108
        ).toString();
109
    }
110
}