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 / ContainsEnvelopeEvaluator.java @ 44043

History | View | Annotate | Download (3.43 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.IProjection;
26
import org.gvsig.expressionevaluator.ExpressionBuilder;
27

    
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.fmap.geom.primitive.Envelope;
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 ContainsEnvelopeEvaluator extends AbstractEvaluator {
38

    
39
    private final Envelope envelope;
40
    private final String geomName;
41
    private final Envelope envelopeTrans;
42
    private final boolean isDefault;
43
    private final ExpressionBuilder builder;
44
    private final IProjection projection;
45
    private final FeatureAttributeDescriptor fad;
46

    
47
    ContainsEnvelopeEvaluator(
48
            Envelope envelope,
49
            IProjection envelopeProjection,
50
            FeatureType featureType,
51
            String geomName,
52
            ExpressionBuilder builder
53
        ) {
54
        fad = (FeatureAttributeDescriptor) featureType.get(geomName);
55
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
56
        this.projection = envelopeProjection;
57
        this.builder = builder;
58
        this.envelope = envelope;
59
        this.envelopeTrans = envelope;
60
        this.geomName = geomName;
61
        this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
62
    }
63

    
64
    @Override
65
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
66
        Envelope featureEnvelope;
67
        if (isDefault) {
68
            featureEnvelope = ((Feature) data.getContextValue("feature"))
69
                    .getDefaultEnvelope();
70

    
71
        } else {
72
            Geometry geom = (Geometry) data.getDataValue(geomName);
73
            if (geom == null) {
74
                return false;
75
            }
76
            featureEnvelope = geom.getEnvelope();
77
        }
78
        return envelopeTrans.contains(featureEnvelope);
79
    }
80

    
81
    @Override
82
    public String getName() {
83
        return "contains in envelope";
84
    }
85

    
86
    @Override
87
    public String getSQL() {
88
        return this.builder.set(
89
                builder.ST_Contains(
90
                        builder.envelope(envelope, projection),
91
                        builder.column(fad.getName())
92
                )
93
        ).toString();
94
    }
95

    
96
}