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

History | View | Annotate | Download (4.45 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.fmap.dal.ExpressionBuilder;
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
/**
37
 *
38
 * @author Vicente Caballero Navarro
39
 *
40
 */
41
public class OverlapsGeometryEvaluator extends AbstractEvaluator {
42

    
43
    private final String geomName;
44
    private final Geometry geometry;
45
    private final Geometry geometryTrans;
46
    private final boolean isDefault;
47
    private final ExpressionBuilder builder;
48
    private final IProjection projection;
49
    private final FeatureAttributeDescriptor fad;
50

    
51
    /**
52
     * @param geometry
53
     * @param projection
54
     * @param featureType
55
     * @param geomName
56
     * @deprecated  use @{link org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory}
57
     */
58
    public OverlapsGeometryEvaluator(
59
            Geometry geometry,
60
            IProjection projection,
61
            FeatureType featureType,
62
            String geomName
63
    ) {
64
        this(
65
                geometry, 
66
                projection, 
67
                featureType, 
68
                geomName, 
69
                SpatialEvaluatorsFactory.getInstance().createBuilder()
70
        );
71
    }   
72
    
73
    OverlapsGeometryEvaluator(
74
            Geometry geometry,
75
            IProjection projection,
76
            FeatureType featureType,
77
            String geomName,
78
            ExpressionBuilder builder
79
        ) {
80
        fad = (FeatureAttributeDescriptor) featureType.get(geomName);
81
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
82
        this.geometry = geometry;
83
        this.geometryTrans = geometry.cloneGeometry();
84
        this.projection = projection;
85
        this.builder = builder;
86
        
87
        IProjection fad_proj = fad.getSRS();
88
        ICoordTrans ct = null;
89

    
90
        if (fad_proj != null && !fad_proj.equals(projection)) {
91
            ct = projection.getCT(fad_proj);
92
        }
93

    
94
        if (ct != null) {
95
            geometryTrans.reProject(ct);
96
        }
97
        this.geomName = geomName;
98

    
99
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
100

    
101
    }
102

    
103
    @Override
104
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
105

    
106
        try {
107
            Geometry geom;
108
            if (isDefault) {
109
                Feature feature = (Feature) data.getContextValue("feature");
110
                geom = feature.getDefaultGeometry();
111

    
112
            } else {
113
                geom = (Geometry) data.getDataValue(geomName);
114
            }
115
            if (geom == null) {
116
                return Boolean.FALSE;
117
            }
118
            return geometryTrans.overlaps(geom);
119

    
120
        } catch (Exception e) {
121
            throw new EvaluatorException(e);
122
        }
123
    }
124

    
125
    @Override
126
    public String getName() {
127
        return "overlaps with geometry";
128
    }
129

    
130
    @Override
131
    public String getSQL() {
132
        return this.builder.set(
133
                builder.ST_Overlaps(
134
                        builder.geometry(geometry, projection),
135
                        builder.column(fad)
136
                )
137
        ).toString();
138
    }
139
    
140
    
141
}