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

History | View | Annotate | Download (3.71 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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontext.layers.vectorial;
25

    
26
import org.cresques.cts.IProjection;
27

    
28
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
29
import org.gvsig.fmap.dal.feature.Feature;
30
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
31
import org.gvsig.fmap.dal.feature.FeatureType;
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.fmap.geom.primitive.Envelope;
36
import org.gvsig.tools.evaluator.AbstractEvaluator;
37
import org.gvsig.tools.evaluator.EvaluatorData;
38
import org.gvsig.tools.evaluator.EvaluatorException;
39

    
40
public class ContainsEnvelopeEvaluator extends AbstractEvaluator {
41

    
42
        private Envelope envelope;
43
        private String geomName;
44
        private Envelope envelopeTrans;
45
        private boolean isDefault;
46
        private String srs;
47
        private String envelopeWKT;
48

    
49
        public ContainsEnvelopeEvaluator(Envelope envelope,
50
                        IProjection envelopeProjection, FeatureType featureType,
51
                        String geomName) {
52
                FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
53
                                .get(geomName);
54

    
55
                this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
56
                                geomName);
57
                this.envelope = envelope;
58
                // this.srs = envelopeProjection.getAbrev();
59
                // this.projection=CRSFactory.getCRS(fad.getSRS());
60
                // this.envelopeProjection=envelopeProjection;
61
//                ICoordTrans ct = null;
62
//                if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n
63
//                        ct = envelopeProjection.getCT(fad.getSRS());
64
//                }
65
//                if (ct != null) {
66
//                        this.envelopeTrans = envelope.convert(ct);
67
//                } else {
68
                        this.envelopeTrans = envelope;
69
//                }
70
                this.geomName = geomName;
71
                this.srs = envelopeProjection.getAbrev();
72
                this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
73

    
74
        }
75

    
76
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
77
                Envelope featureEnvelope;
78
                if (isDefault) {
79
                        featureEnvelope = ((Feature) data.getContextValue("feature"))
80
                                        .getDefaultEnvelope();
81

    
82
                } else {
83
                        featureEnvelope = ((Geometry) data.getDataValue(geomName))
84
                                        .getEnvelope();
85
                }
86
                return new Boolean(envelopeTrans.contains(featureEnvelope));
87
        }
88

    
89
        public String getName() {
90
                return "contains in envelope";
91
        }
92

    
93
        public String getSQL() {
94
                if (envelopeWKT == null) {
95
                        try {
96
                                envelopeWKT = envelope.getGeometry().convertToWKT();
97
                        } catch (GeometryOperationNotSupportedException e) {
98
                                throw new DataEvaluatorRuntimeException(e);
99
                        } catch (GeometryOperationException e) {
100
                                throw new DataEvaluatorRuntimeException(e);
101
                        }
102
                }
103
                return " ST_contains(ST_GeomFromText('" + envelopeWKT + "', '" + srs
104
                                + "'), ST_envelope(" + geomName + ")) ";
105
        }
106

    
107
}