Revision 43020 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/IntersectsEnvelopeEvaluator.java

View differences:

IntersectsEnvelopeEvaluator.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
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 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.
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 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.
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.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.fmap.mapcontext.layers.vectorial;
25 24

  
26 25
import org.cresques.cts.IProjection;
26
import org.gvsig.fmap.dal.ExpressionBuilder;
27 27

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

  
40 37
public class IntersectsEnvelopeEvaluator extends AbstractEvaluator {
41 38

  
42
	private Envelope envelope;
43
	private String geomName;
44
	private String envelopeWKT = null;
45
	private Envelope envelopeTrans;
46
	private boolean isDefault;
47
	private String srs;
48
	String defaultGeometryAttributeName;
39
    private Envelope envelope;
40
    private String geomName;
41
    private boolean isDefault;
42
    private ExpressionBuilder condition;
43
    String defaultGeometryAttributeName;
44
    
49 45

  
50
	public IntersectsEnvelopeEvaluator(Envelope envelope,
51
			IProjection envelopeProjection, FeatureType featureType,
52
			String geomName) {
53
		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
54
				.get(geomName);
46
    IntersectsEnvelopeEvaluator(Envelope envelope,
47
            IProjection envelopeProjection, FeatureType featureType,
48
            String geomName,
49
            ExpressionBuilder builder) {
50
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType.get(geomName);
51
        defaultGeometryAttributeName = featureType.getDefaultGeometryAttributeName();
52
        this.isDefault = defaultGeometryAttributeName.equals(geomName);
53
        this.envelope = envelope;
54
        this.geomName = geomName;
55
        this.getFieldsInfo().addMatchFieldValue(geomName, envelope);
55 56

  
56
		defaultGeometryAttributeName = featureType.getDefaultGeometryAttributeName();
57
        this.isDefault = defaultGeometryAttributeName.equals(
58
				geomName);
59
		this.envelope = envelope;
60
		// this.srs = envelopeProjection.getAbrev();
61
		// this.projection=CRSFactory.getCRS(fad.getSRS());
62
		// this.envelopeProjection=envelopeProjection;
63
//		ICoordTrans ct = null;
64
//		if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci?n
65
//			ct = envelopeProjection.getCT(fad.getSRS());
66
//		}
67
//		if (ct != null) {
68
//			this.envelopeTrans = envelope.convert(ct);
69
//		} else {
70
			this.envelopeTrans = envelope;
71
//		}
72
		this.geomName = geomName;
57
        this.condition = builder.set(
58
                builder.ST_Intersects(
59
                        builder.geometry(envelope.getGeometry(), envelopeProjection), 
60
                        builder.ST_Envelope(builder.column(geomName))
61
                )
62
        );
63
    }
73 64

  
74
		this.srs = envelopeProjection.getAbrev();
75

  
76
		this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
77

  
78
	}
79

  
65
    @Override
80 66
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
81 67
        Envelope featureEnvelope;
82
        Geometry geom = null;
68
        Geometry geom ;
83 69
        if (isDefault) {
84 70
            geom = (Geometry) data.getDataValue(defaultGeometryAttributeName);
85 71
            featureEnvelope = ((Feature) data.getContextValue("feature")).getDefaultEnvelope();
......
90 76
            }
91 77
            featureEnvelope = geom.getEnvelope();
92 78
        }
93
        if (envelopeTrans.intersects(featureEnvelope)) {
94
            return new Boolean(envelopeTrans.intersects(geom));
79
        if (envelope.intersects(featureEnvelope)) {
80
            return envelope.intersects(geom);
95 81
        }
96 82
        return Boolean.FALSE;
97 83
    }
98 84

  
99
	public String getName() {
100
		return "intersects envelope";
101
	}
85
    @Override
86
    public String getName() {
87
        return "intersects envelope";
88
    }
102 89

  
103
	public String getSQL() {
104

  
105
		if (envelopeWKT == null) {
106
			try {
107
				envelopeWKT = (String) envelope.getGeometry().convertToWKT();
108
			} catch (GeometryOperationNotSupportedException e) {
109
				throw new DataEvaluatorRuntimeException(e);
110
			} catch (GeometryOperationException e) {
111
				throw new DataEvaluatorRuntimeException(e);
112
			}
113
		}
114

  
115
		return " ST_intersects(ST_GeomFromText('" + envelopeWKT + "', '" + srs
116
				+ "'), ST_envelope(" + geomName + ")) ";
117
	}
118

  
90
    @Override
91
    public String getSQL() {
92
        return this.condition.toString();
93
    }
119 94
}

Also available in: Unified diff