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

History | View | Annotate | Download (3.85 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.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
    OverlapsGeometryEvaluator(
52
            Geometry geometry,
53
            IProjection projection,
54
            FeatureType featureType,
55
            String geomName,
56
            ExpressionBuilder builder
57
        ) {
58
        fad = (FeatureAttributeDescriptor) featureType.get(geomName);
59
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
60
        this.geometry = geometry;
61
        this.geometryTrans = geometry.cloneGeometry();
62
        this.projection = projection;
63
        this.builder = builder;
64
        
65
        IProjection fad_proj = fad.getSRS();
66
        ICoordTrans ct = null;
67

    
68
        if (fad_proj != null && !fad_proj.equals(projection)) {
69
            ct = projection.getCT(fad_proj);
70
        }
71

    
72
        if (ct != null) {
73
            geometryTrans.reProject(ct);
74
        }
75
        this.geomName = geomName;
76

    
77
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
78

    
79
    }
80

    
81
    @Override
82
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
83

    
84
        try {
85
            Geometry geom;
86
            if (isDefault) {
87
                Feature feature = (Feature) data.getContextValue("feature");
88
                geom = feature.getDefaultGeometry();
89

    
90
            } else {
91
                geom = (Geometry) data.getDataValue(geomName);
92
            }
93
            if (geom == null) {
94
                return Boolean.FALSE;
95
            }
96
            return geometryTrans.overlaps(geom);
97

    
98
        } catch (Exception e) {
99
            throw new EvaluatorException(e);
100
        }
101
    }
102

    
103
    @Override
104
    public String getName() {
105
        return "overlaps with geometry";
106
    }
107

    
108
    @Override
109
    public String getSQL() {
110
        return this.builder.set(
111
                builder.ST_Overlaps(
112
                        builder.geometry(geometry, projection),
113
                        builder.column(fad.getName())
114
                )
115
        ).toString();
116
    }
117
    
118
    
119
}