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

History | View | Annotate | Download (4.46 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 43040 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 43040 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 43040 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 43040 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.IProjection;
26 43040 jjdelcerro
import org.gvsig.fmap.dal.ExpressionBuilder;
27 40435 jjdelcerro
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 43040 jjdelcerro
    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 40435 jjdelcerro
46 43040 jjdelcerro
    /**
47
     * @deprecated  use @{link org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory}
48
     * @param envelope
49
     * @param envelopeProjection
50
     * @param featureType
51
     * @param geomName
52
     */
53
    public ContainsEnvelopeEvaluator(
54
            Envelope envelope,
55
            IProjection envelopeProjection,
56
            FeatureType featureType,
57
            String geomName
58
        ) {
59
        this(
60
                envelope,
61
                envelopeProjection,
62
                featureType,
63
                geomName,
64
                SpatialEvaluatorsFactory.getInstance().createBuilder()
65
        );
66
    }
67
68
    ContainsEnvelopeEvaluator(
69
            Envelope envelope,
70
            IProjection envelopeProjection,
71
            FeatureType featureType,
72
            String geomName,
73
            ExpressionBuilder builder
74
        ) {
75
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
76
                .get(geomName);
77
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
78
        this.projection = envelopeProjection;
79
        this.builder = builder;
80
        this.envelope = envelope;
81
        // this.srs = envelopeProjection.getAbrev();
82
        // this.projection=CRSFactory.getCRS(fad.getSRS());
83
        // this.envelopeProjection=envelopeProjection;
84 40435 jjdelcerro
//                ICoordTrans ct = null;
85
//                if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n
86
//                        ct = envelopeProjection.getCT(fad.getSRS());
87
//                }
88
//                if (ct != null) {
89
//                        this.envelopeTrans = envelope.convert(ct);
90
//                } else {
91 43040 jjdelcerro
        this.envelopeTrans = envelope;
92 40435 jjdelcerro
//                }
93 43040 jjdelcerro
        this.geomName = geomName;
94
        this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
95 40435 jjdelcerro
96 43040 jjdelcerro
    }
97 40435 jjdelcerro
98 43040 jjdelcerro
    @Override
99
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
100
        Envelope featureEnvelope;
101
        if (isDefault) {
102
            featureEnvelope = ((Feature) data.getContextValue("feature"))
103
                    .getDefaultEnvelope();
104 40435 jjdelcerro
105 43040 jjdelcerro
        } else {
106
            Geometry geom = (Geometry) data.getDataValue(geomName);
107
            if (geom == null) {
108
                return false;
109
            }
110
            featureEnvelope = geom.getEnvelope();
111
        }
112
        return envelopeTrans.contains(featureEnvelope);
113
    }
114 40435 jjdelcerro
115 43040 jjdelcerro
    @Override
116
    public String getName() {
117
        return "contains in envelope";
118
    }
119 40435 jjdelcerro
120 43040 jjdelcerro
    @Override
121
    public String getSQL() {
122
        return this.builder.set(
123
                builder.ST_Contains(
124
                        builder.envelope(envelope, projection),
125
                        builder.column(geomName)
126
                )
127
        ).toString();
128
    }
129 40435 jjdelcerro
130
}