Revision 43034

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/ExpressionBuilder.java
1 1
package org.gvsig.fmap.dal;
2 2

  
3
import java.beans.Expression;
4 3
import java.util.List;
5 4
import org.cresques.cts.IProjection;
6 5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.geom.primitive.Envelope;
7 7

  
8 8
public interface ExpressionBuilder {
9 9

  
......
49 49
        public final static String ST_Contains = "ST_Contains";
50 50
        public final static String ST_Crosses = "ST_Crosses";
51 51
        public final static String ST_Disjoint = "ST_Disjoint";
52
        public final static String ST_Equals = "ST_Equals";
52 53
        public final static String ST_IsClosed = "ST_IsClosed";
53 54
        public final static String ST_Overlaps = "ST_Overlaps";
54 55
        public final static String ST_Touches = "ST_Touches";
......
185 186

  
186 187
    public GeometryValue geometry(Geometry geom, IProjection projection);
187 188

  
189
    public GeometryValue envelope(Envelope envelope, IProjection projection);
190

  
188 191
    public Custom custom(Object value);
189 192
    
190 193
    public Constant srs(IProjection projection);
......
199 202
    public Function isNull(Value value);
200 203

  
201 204
    public Function Find_SRID(Value schema, Value table, Value column);
202
            
205
    
203 206
    public Function ST_SRID(Value geom);
204 207
    
205 208
    public Function ST_AsText(Value geom);
......
216 219
            
217 220
    public Function ST_GeomFromEWKB(Value geom, Value crs);
218 221

  
222
    public Function ST_Equals(Value geom1, Value geom2);
223

  
219 224
    public Function ST_Intersects(Value geom1, Value geom2);
220 225

  
221 226
    public Function ST_Contains(Value geom1, Value geom2);
222 227

  
228
    public Function ST_Disjoint(Value geom1, Value geom2);
229

  
223 230
    public Function ST_Crosses(Value geom1, Value geom2);
224 231

  
225 232
    public Function ST_IsClosed(Value geom1);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/ExpressionBuilderBase.java
29 29
import org.gvsig.fmap.dal.ExpressionBuilder.Visitor;
30 30
import org.gvsig.fmap.dal.ExpressionBuilder.VisitorFilter;
31 31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.primitive.Envelope;
32 33

  
33 34
public class ExpressionBuilderBase implements ExpressionBuilder {
34 35
    public class ConfigBase implements Config {
......
53 54
            this.values.put(ST_AsEWKB, "ST_AsWKB({0})");
54 55
            this.values.put(ST_Contains, "ST_Contains(({0}), ({1}))");            
55 56
            this.values.put(ST_Crosses,  "ST_Crosses(({0}), ({1}))");
56
            this.values.put(ST_Disjoint ,  "ST_Disjoint (({0}), ({1}))");
57
            this.values.put(ST_Disjoint ,  "ST_Disjoint(({0}), ({1}))");
58
            this.values.put(ST_Equals ,  "ST_Equals(({0}), ({1}))");
57 59
            this.values.put(ST_IsClosed,  "ST_IsClosed({0})");
58 60
            this.values.put(ST_Overlaps,  "ST_Overlaps(({0}), ({1}))");
59 61
            this.values.put(ST_Touches,  "ST_Touches(({0}), ({1}))");
......
664 666
    @Override
665 667
    public String string(String s) {
666 668
        String quote = this.config.getString(Config.quote_for_strings);
669
//        No se porque no esta disponible wrapIfMissing
670
//        return StringUtils.wrapIfMissing(s,quote);
667 671
        if (s.startsWith(quote)) {
668 672
            return s;
669 673
        }
......
673 677
    @Override
674 678
    public String identifier(String id) {
675 679
        String quote = this.config.getString(Config.quote_for_identifiers);
680
//        No se porque no esta disponible wrapIfMissing
681
//        return StringUtils.wrapIfMissing(id,quote);
676 682
        if (id.startsWith(quote)) {
677 683
            return id;
678 684
        }
......
732 738
    }
733 739

  
734 740
    @Override
741
    public GeometryValue envelope(Envelope envelope, IProjection projection) {
742
        return new GeometryValueBase(envelope.getGeometry(), projection);
743
    }
744

  
745
    @Override
735 746
    public Custom custom(Object value) {
736 747
        return new CustomBase(value);
737 748
    }
......
859 870
    }
860 871

  
861 872
    @Override
873
    public Function ST_Disjoint(Value geom1, Value geom2) {
874
        return function("ST_Disjoint", config.getString(Config.ST_Disjoint), geom1, geom2);
875
    }
876
    
877
    @Override
862 878
    public Function ST_Contains(Value geom1, Value geom2) {
863 879
        return function("ST_Contains", config.getString(Config.ST_Contains), geom1, geom2);
864 880
    }
865 881

  
866 882
    @Override
883
    public Function ST_Equals(Value geom1, Value geom2) {
884
        return function("ST_Equals", config.getString(Config.ST_Equals), geom1, geom2);
885
    }
886

  
887
    @Override
867 888
    public Function ST_Crosses(Value geom1, Value geom2) {
868 889
        return function("ST_Crosses", config.getString(Config.ST_Crosses), geom1, geom2);
869 890
    }
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/EqualsGeometryEvaluator.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.ICoordTrans;
27 26
import org.cresques.cts.IProjection;
28
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
27
import org.gvsig.fmap.dal.ExpressionBuilder;
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.tools.evaluator.AbstractEvaluator;
36 33
import org.gvsig.tools.evaluator.EvaluatorData;
37 34
import org.gvsig.tools.evaluator.EvaluatorException;
38
/**
39
 *
40
 * @author Vicente Caballero Navarro
41
 *
42
 */
35

  
43 36
public class EqualsGeometryEvaluator extends AbstractEvaluator {
44 37

  
45
	private String geomName;
46
	private Geometry geometry;
47
	private String geometryWKT = null;
48
	private Geometry geometryTrans;
49
	private String srs;
50
	private boolean isDefault;
38
    private final String geomName;
39
    private final Geometry geometry;
40
    private final Geometry geometryTrans;
41
    private final boolean isDefault;
42
    private final ExpressionBuilder builder;
43
    private final IProjection projection;
51 44

  
52
	EqualsGeometryEvaluator(Geometry geometry,
53
			IProjection projection, FeatureType featureType,
54
			String geomName) {
55
		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
56
				.get(geomName);
57
		this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
58
				geomName);
59
		this.geometry = geometry;
60
		this.geometryTrans = geometry.cloneGeometry();
61
		this.srs = projection.getAbrev();
62
		
63
		IProjection fad_proj = fad.getSRS();
64
		ICoordTrans ct = null;
65
		
66
		if (fad_proj != null && !fad_proj.equals(projection)) {
67
		    ct = projection.getCT(fad_proj);
68
		}
45
    EqualsGeometryEvaluator(
46
            Geometry geometry,
47
            IProjection projection,
48
            FeatureType featureType,
49
            String geomName,
50
            ExpressionBuilder builder
51
    ) {
52
        this.builder = builder;
53
        this.projection = projection;
54
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
55
                .get(geomName);
56
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
57
        this.geometry = geometry;
58
        this.geometryTrans = geometry.cloneGeometry();
69 59

  
70
		if (ct != null) {
71
			geometryTrans.reProject(ct);
72
		}
73
		this.geomName = geomName;
60
        IProjection fad_proj = fad.getSRS();
61
        ICoordTrans ct = null;
74 62

  
75
		this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
63
        if (fad_proj != null && !fad_proj.equals(projection)) {
64
            ct = projection.getCT(fad_proj);
65
        }
76 66

  
77
	}
67
        if (ct != null) {
68
            geometryTrans.reProject(ct);
69
        }
70
        this.geomName = geomName;
78 71

  
79
	public Object evaluate(EvaluatorData data) throws EvaluatorException {
80
		try {
81
			Geometry geom = null;
82
			if (isDefault) {
83
				Feature feature = (Feature) data.getContextValue("feature");
84
				geom =feature.getDefaultGeometry();
72
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
85 73

  
86
			} else {
87
				geom = (Geometry) data.getDataValue(geomName);
88
			}
89
                        if ( geom == null ) {
90
                            return Boolean.FALSE;
91
                        }
92
			return new Boolean(geometryTrans.equals(geom));
74
    }
93 75

  
94
		} catch (Exception e) {
95
			throw new EvaluatorException(e);
96
		}
97
	}
76
    @Override
77
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
78
        try {
79
            Geometry geom;
80
            if (isDefault) {
81
                Feature feature = (Feature) data.getContextValue("feature");
82
                geom = feature.getDefaultGeometry();
98 83

  
99
	public String getName() {
100
		return "equals with geometry";
101
	}
84
            } else {
85
                geom = (Geometry) data.getDataValue(geomName);
86
            }
87
            if (geom == null) {
88
                return Boolean.FALSE;
89
            }
90
            return geometryTrans.equals(geom);
102 91

  
103
	public String getSQL() {
104
		if (geometryWKT == null) {
105
			try {
106
				geometryWKT = geometry.convertToWKT();
107
			} catch (GeometryOperationNotSupportedException e) {
108
				throw new DataEvaluatorRuntimeException(e);
109
			} catch (GeometryOperationException e) {
110
				throw new DataEvaluatorRuntimeException(e);
111
			}
112
		}
113
		return " ST_equals(ST_GeomFromText('" + geometryWKT + "', " + "'"
114
				+ srs + "'" + "), " + geomName + ") ";
115
	}
92
        } catch (Exception e) {
93
            throw new EvaluatorException(e);
94
        }
95
    }
116 96

  
97
    @Override
98
    public String getName() {
99
        return "equals with geometry";
100
    }
101

  
102
    @Override
103
    public String getSQL() {
104
        return this.builder.set(
105
                builder.ST_Equals(
106
                        builder.geometry(geometry, projection),
107
                        builder.column(geomName)
108
                )
109
        ).toString();
110
    }
111

  
117 112
}
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
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.ICoordTrans;
27 26
import org.cresques.cts.IProjection;
27
import org.gvsig.fmap.dal.ExpressionBuilder;
28 28
import org.gvsig.fmap.dal.feature.Feature;
29 29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
30 30
import org.gvsig.fmap.dal.feature.FeatureType;
......
32 32
import org.gvsig.tools.evaluator.AbstractEvaluator;
33 33
import org.gvsig.tools.evaluator.EvaluatorData;
34 34
import org.gvsig.tools.evaluator.EvaluatorException;
35

  
35 36
/**
36 37
 *
37 38
 * @author Vicente Caballero Navarro
......
39 40
 */
40 41
public class OverlapsGeometryEvaluator extends AbstractEvaluator {
41 42

  
42
	private String geomName;
43
	private Geometry geometry;
44
	private Geometry geometryTrans;
45
	private String srs;
46
	private boolean isDefault;
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;
47 49

  
48
	OverlapsGeometryEvaluator(Geometry geometry,
49
			IProjection envelopeProjection, FeatureType featureType,
50
			String geomName) {
51
		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
52
				.get(geomName);
53
		this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
54
				geomName);
55
		this.geometry = geometry;
56
		this.geometryTrans = geometry.cloneGeometry();
57
		this.srs = envelopeProjection.getAbrev();
58
		
59
		IProjection fad_proj = fad.getSRS();
60
		ICoordTrans ct = null;
61
		
62
		if (fad_proj != null && !fad_proj.equals(envelopeProjection)) {
63
		    ct = envelopeProjection.getCT(fad_proj);
64
		}
65
		
66
		if (ct != null) {
67
			geometryTrans.reProject(ct);
68
		}
69
		this.geomName = geomName;
50
    OverlapsGeometryEvaluator(
51
            Geometry geometry,
52
            IProjection projection,
53
            FeatureType featureType,
54
            String geomName,
55
            ExpressionBuilder builder
56
        ) {
57
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
58
                .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;
70 67

  
71
		this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
68
        if (fad_proj != null && !fad_proj.equals(projection)) {
69
            ct = projection.getCT(fad_proj);
70
        }
72 71

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

  
75
	public Object evaluate(EvaluatorData data) throws EvaluatorException {
77
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
76 78

  
77
		try {
78
			Geometry geom = null;
79
			if (isDefault) {
80
				Feature feature = (Feature) data.getContextValue("feature");
81
				geom = feature.getDefaultGeometry();
79
    }
82 80

  
83
			} else {
84
				geom = (Geometry) data.getDataValue(geomName);
85
			}
86
                        if ( geom == null ) {
87
                            return Boolean.FALSE;
88
                        }
89
			return new Boolean(geometryTrans.overlaps(geom));
81
    @Override
82
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
90 83

  
91
		} catch (Exception e) {
92
			throw new EvaluatorException(e);
93
		}
94
	}
84
        try {
85
            Geometry geom;
86
            if (isDefault) {
87
                Feature feature = (Feature) data.getContextValue("feature");
88
                geom = feature.getDefaultGeometry();
95 89

  
96
	public String getName() {
97
		return "overlaps with geometry";
98
	}
90
            } else {
91
                geom = (Geometry) data.getDataValue(geomName);
92
            }
93
            if (geom == null) {
94
                return Boolean.FALSE;
95
            }
96
            return geometryTrans.overlaps(geom);
99 97

  
100
	public String getSQL() {
101
		return " ST_overlaps(ST_GeomFromText('" + geometry.toString() + "', " + "'"
102
				+ srs + "'" + "), " + geomName + ") ";
103
	}
98
        } catch (Exception e) {
99
            throw new EvaluatorException(e);
100
        }
101
    }
104 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(geomName)
114
                )
115
        ).toString();
116
    }
117
    
118
    
105 119
}
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/SpatialEvaluatorsFactory.java
22 22
        
23 23
    }
24 24
    
25
    public Evaluator intersects(Geometry geometry,
26
        IProjection projection, 
27
        FeatureType featureType,
28
        String geomName,
29
        ExpressionBuilder builder) {
25
    public Evaluator intersects(
26
            Geometry geometry,
27
            IProjection projection, 
28
            FeatureType featureType,
29
            String geomName,
30
            ExpressionBuilder builder
31
        ) {
30 32
        return new IntersectsGeometryEvaluator(geometry, projection, featureType, geomName, builder);
31 33
    }
32 34
    
33
    public Evaluator intersects(Envelope envelope,
34
        IProjection projection, 
35
        FeatureType featureType,
36
        String geomName,
37
        ExpressionBuilder builder) {
35
    public Evaluator intersects(
36
            Envelope envelope,
37
            IProjection projection, 
38
            FeatureType featureType,
39
            String geomName,
40
            ExpressionBuilder builder
41
        ) {
38 42
        return new IntersectsEnvelopeEvaluator(envelope, projection, featureType, geomName, builder);
39 43
    }
40 44
    
41
    public Evaluator intersects(Geometry geometry,
42
        IProjection projection, 
43
        FeatureStore store) {
44
        
45
        
45
    public Evaluator intersects(
46
            Geometry geometry,
47
            IProjection projection, 
48
            FeatureStore store
49
        ) {
46 50
        try {
47 51
            FeatureType featureType = store.getDefaultFeatureType();
48 52
            String geomName = featureType.getDefaultGeometryAttributeName();
......
53 57
        }
54 58
    }
55 59

  
56
    public Evaluator intersects(Envelope envelope,
57
        IProjection projection, 
58
        FeatureStore store) {
60
    public Evaluator intersects(
61
            Envelope envelope,
62
            IProjection projection, 
63
            FeatureStore store
64
        ) {
59 65
        try {
60 66
            FeatureType featureType = store.getDefaultFeatureType();
61 67
            String geomName = featureType.getDefaultGeometryAttributeName();
......
66 72
        }
67 73
    }
68 74

  
69
    public Evaluator contains(Envelope envelope,
70
        IProjection projection, 
71
        FeatureType featureType,
72
        String geomName,
73
        ExpressionBuilder builder){
75
    public Evaluator contains(
76
            Envelope envelope,
77
            IProjection projection, 
78
            FeatureType featureType,
79
            String geomName,
80
            ExpressionBuilder builder
81
        ){
74 82
        return new ContainsEnvelopeEvaluator(envelope, projection, featureType, geomName);
75 83
    }
76 84

  
77
    public Evaluator contains(Geometry geometry,
78
        IProjection projection, 
79
        FeatureType featureType,
80
        String geomName,
81
        ExpressionBuilder builder){
82
        return new ContainsGeometryEvaluator(geometry, projection, featureType, geomName);
85
    public Evaluator contains(
86
            Geometry geometry,
87
            IProjection projection, 
88
            FeatureType featureType,
89
            String geomName,
90
            ExpressionBuilder builder
91
        ){
92
        return new ContainsGeometryEvaluator(geometry, projection, featureType, geomName, builder);
83 93
    }
84 94
    
85
    public Evaluator contains(Geometry geometry,
86
        IProjection projection, 
87
        FeatureStore store) {
95
    public Evaluator contains(
96
            Geometry geometry,
97
            IProjection projection, 
98
            FeatureStore store
99
        ) {
88 100
        try {
89 101
            FeatureType featureType = store.getDefaultFeatureType();
90 102
            String geomName = featureType.getDefaultGeometryAttributeName();
91 103
            ExpressionBuilder builder = store.createExpressionBuilder();
92
            return contains(geometry, projection, featureType, geomName,builder);
104
            return this.contains(geometry, projection, featureType, geomName,builder);
93 105
        } catch (DataException ex) {
94 106
            throw new RuntimeException("Can't create contains evaluator.",ex);
95 107
        }
96 108
    }
97 109

  
98
    public Evaluator contains(Envelope envelope,
99
        IProjection projection, 
100
        FeatureStore store) {
110
    public Evaluator contains(
111
            Envelope envelope,
112
            IProjection projection, 
113
            FeatureStore store
114
        ) {
101 115
        try {
102 116
            FeatureType featureType = store.getDefaultFeatureType();
103 117
            String geomName = featureType.getDefaultGeometryAttributeName();
104 118
            ExpressionBuilder builder = store.createExpressionBuilder();
105
            return contains(envelope, projection, featureType, geomName,builder);
119
            return this.contains(envelope, projection, featureType, geomName,builder);
106 120
        } catch (DataException ex) {
107 121
            throw new RuntimeException("Can't create contains evaluator.",ex);
108 122
        }
109 123
    }
110 124

  
111
    public Evaluator not_contains(Geometry geometry,
112
        IProjection projection, 
113
        FeatureType featureType,
114
        String geomName,
115
        ExpressionBuilder builder){
116
        return new OutGeometryEvaluator(geometry, projection, featureType, geomName);
125
    public Evaluator not_contains(
126
            Geometry geometry,
127
            IProjection projection, 
128
            FeatureType featureType,
129
            String geomName,
130
            ExpressionBuilder builder
131
        ){
132
        return new OutGeometryEvaluator(geometry, projection, featureType, geomName, builder);
117 133
    }
118 134
    
119
    public Evaluator not_contains(Geometry geometry,
120
        IProjection projection, 
121
        FeatureStore store) {
135
    public Evaluator not_contains(
136
            Geometry geometry,
137
            IProjection projection, 
138
            FeatureStore store
139
        ) {
122 140
        try {
123 141
            FeatureType featureType = store.getDefaultFeatureType();
124 142
            String geomName = featureType.getDefaultGeometryAttributeName();
125 143
            ExpressionBuilder builder = store.createExpressionBuilder();
126
            return not_contains(geometry, projection, featureType, geomName,builder);
144
            return this.not_contains(geometry, projection, featureType, geomName,builder);
127 145
        } catch (DataException ex) {
128 146
            throw new RuntimeException("Can't create not_contains evaluator.",ex);
129 147
        }
130 148
    }
131 149

  
132
    public Evaluator crosses(Geometry geometry,
133
        IProjection projection, 
134
        FeatureType featureType,
135
        String geomName,
136
        ExpressionBuilder builder) {
137
        return new CrossesGeometryEvaluator(geometry, projection, featureType, geomName);
150
    public Evaluator crosses(
151
            Geometry geometry,
152
            IProjection projection, 
153
            FeatureType featureType,
154
            String geomName,
155
            ExpressionBuilder builder
156
        ) {
157
        return new CrossesGeometryEvaluator(geometry, projection, featureType, geomName, builder);
138 158
    }
139 159

  
140
    public Evaluator crosses(Envelope envelope,
141
        IProjection projection, 
142
        FeatureType featureType,
143
        String geomName,
144
        ExpressionBuilder builder) {
145
        return new CrossEnvelopeEvaluator(envelope, projection, featureType, geomName);
160
    public Evaluator crosses(
161
            Envelope envelope,
162
            IProjection projection, 
163
            FeatureType featureType,
164
            String geomName,
165
            ExpressionBuilder builder
166
        ) {
167
        return new CrossEnvelopeEvaluator(envelope, projection, featureType, geomName, builder);
146 168
    }
147 169

  
148
    public Evaluator crosses(Geometry geometry,
149
        IProjection projection, 
150
        FeatureStore store) {
170
    public Evaluator crosses(
171
            Geometry geometry,
172
            IProjection projection, 
173
            FeatureStore store
174
        ) {
151 175
        try {
152 176
            FeatureType featureType = store.getDefaultFeatureType();
153 177
            String geomName = featureType.getDefaultGeometryAttributeName();
154 178
            ExpressionBuilder builder = store.createExpressionBuilder();
155
            return crosses(geometry, projection, featureType, geomName,builder);
179
            return this.crosses(geometry, projection, featureType, geomName,builder);
156 180
        } catch (DataException ex) {
157 181
            throw new RuntimeException("Can't create crosses evaluator.",ex);
158 182
        }
159 183
    }
160 184

  
161
    public Evaluator crosses(Envelope envelope,
162
        IProjection projection, 
163
        FeatureStore store) {
185
    public Evaluator crosses(
186
            Envelope envelope,
187
            IProjection projection, 
188
            FeatureStore store
189
        ) {
164 190
        try {
165 191
            FeatureType featureType = store.getDefaultFeatureType();
166 192
            String geomName = featureType.getDefaultGeometryAttributeName();
167 193
            ExpressionBuilder builder = store.createExpressionBuilder();
168
            return crosses(envelope, projection, featureType, geomName,builder);
194
            return this.crosses(envelope, projection, featureType, geomName,builder);
169 195
        } catch (DataException ex) {
170 196
            throw new RuntimeException("Can't create crosses evaluator.",ex);
171 197
        }
172 198
    }
173 199

  
174
    public Evaluator disjoint(Geometry geometry,
175
        IProjection projection, 
176
        FeatureType featureType,
177
        String geomName,
178
        ExpressionBuilder builder) {
179
        return new DisjointGeometryEvaluator(geometry, projection, featureType, geomName);
200
    public Evaluator disjoint(
201
            Geometry geometry,
202
            IProjection projection, 
203
            FeatureType featureType,
204
            String geomName,
205
            ExpressionBuilder builder
206
        ) {
207
        return new DisjointGeometryEvaluator(geometry, projection, featureType, geomName, builder);
180 208
    }    
181 209

  
182
    public Evaluator disjoint(Geometry geometry,
183
        IProjection projection, 
184
        FeatureStore store) {
210
    public Evaluator disjoint(
211
            Geometry geometry,
212
            IProjection projection, 
213
            FeatureStore store
214
        ) {
185 215
        try {
186 216
            FeatureType featureType = store.getDefaultFeatureType();
187 217
            String geomName = featureType.getDefaultGeometryAttributeName();
188 218
            ExpressionBuilder builder = store.createExpressionBuilder();
189
            return disjoint(geometry, projection, featureType, geomName,builder);
219
            return this.disjoint(geometry, projection, featureType, geomName,builder);
190 220
        } catch (DataException ex) {
191 221
            throw new RuntimeException("Can't create disjoint evaluator.",ex);
192 222
        }
193 223
    }
194 224
    
195
    public Evaluator overlaps(Geometry geometry,
196
        IProjection projection, 
197
        FeatureType featureType,
198
        String geomName,
199
        ExpressionBuilder builder) {
200
        return new OverlapsGeometryEvaluator(geometry, projection, featureType, geomName);
225
    public Evaluator overlaps(
226
            Geometry geometry,
227
            IProjection projection, 
228
            FeatureType featureType,
229
            String geomName,
230
            ExpressionBuilder builder
231
        ) {
232
        return new OverlapsGeometryEvaluator(geometry, projection, featureType, geomName, builder);
201 233
    }    
202 234

  
203
    public Evaluator overlaps(Geometry geometry,
204
        IProjection projection, 
205
        FeatureStore store) {
235
    public Evaluator overlaps(
236
            Geometry geometry,
237
            IProjection projection, 
238
            FeatureStore store
239
        ) {
206 240
        try {
207 241
            FeatureType featureType = store.getDefaultFeatureType();
208 242
            String geomName = featureType.getDefaultGeometryAttributeName();
209 243
            ExpressionBuilder builder = store.createExpressionBuilder();
210
            return overlaps(geometry, projection, featureType, geomName,builder);
244
            return this.overlaps(geometry, projection, featureType, geomName,builder);
211 245
        } catch (DataException ex) {
212 246
            throw new RuntimeException("Can't create overlaps evaluator.",ex);
213 247
        }
214 248
    }
215 249
    
216
    public Evaluator touches(Geometry geometry,
217
        IProjection projection, 
218
        FeatureType featureType,
219
        String geomName,
220
        ExpressionBuilder builder) {
221
        return new TouchesGeometryEvaluator(geometry, projection, featureType, geomName);
250
    public Evaluator touches(
251
            Geometry geometry,
252
            IProjection projection, 
253
            FeatureType featureType,
254
            String geomName,
255
            ExpressionBuilder builder
256
        ) {
257
        return new TouchesGeometryEvaluator(geometry, projection, featureType, geomName,builder);
222 258
    }    
223 259

  
224
    public Evaluator touches(Geometry geometry,
225
        IProjection projection, 
226
        FeatureStore store) {
260
    public Evaluator touches(
261
            Geometry geometry,
262
            IProjection projection, 
263
            FeatureStore store
264
        ) {
227 265
        try {
228 266
            FeatureType featureType = store.getDefaultFeatureType();
229 267
            String geomName = featureType.getDefaultGeometryAttributeName();
230 268
            ExpressionBuilder builder = store.createExpressionBuilder();
231
            return touches(geometry, projection, featureType, geomName,builder);
269
            return this.touches(geometry, projection, featureType, geomName,builder);
232 270
        } catch (DataException ex) {
233 271
            throw new RuntimeException("Can't create touches evaluator.",ex);
234 272
        }
235 273
    }
236 274
    
237
    public Evaluator within(Geometry geometry,
238
        IProjection projection, 
239
        FeatureType featureType,
240
        String geomName,
241
        ExpressionBuilder builder) {
242
        return new WithinGeometryEvaluator(geometry, projection, featureType, geomName);
275
    public Evaluator within(
276
            Geometry geometry,
277
            IProjection projection, 
278
            FeatureType featureType,
279
            String geomName,
280
            ExpressionBuilder builder
281
        ) {
282
        return new WithinGeometryEvaluator(geometry, projection, featureType, geomName,builder);
243 283
    }    
244 284

  
245
    public Evaluator within(Geometry geometry,
246
        IProjection projection, 
247
        FeatureStore store) {
285
    public Evaluator within(
286
            Geometry geometry,
287
            IProjection projection, 
288
            FeatureStore store
289
        ) {
248 290
        try {
249 291
            FeatureType featureType = store.getDefaultFeatureType();
250 292
            String geomName = featureType.getDefaultGeometryAttributeName();
251 293
            ExpressionBuilder builder = store.createExpressionBuilder();
252
            return within(geometry, projection, featureType, geomName,builder);
294
            return this.within(geometry, projection, featureType, geomName,builder);
253 295
        } catch (DataException ex) {
254 296
            throw new RuntimeException("Can't create within evaluator.",ex);
255 297
        }
256 298
    }
257 299
    
258
    public Evaluator equals(Geometry geometry,
259
        IProjection projection, 
260
        FeatureType featureType,
261
        String geomName,
262
        ExpressionBuilder builder) {
263
        return new EqualsGeometryEvaluator(geometry, projection, featureType, geomName);
300
    public Evaluator equals(
301
            Geometry geometry,
302
            IProjection projection, 
303
            FeatureType featureType,
304
            String geomName,
305
            ExpressionBuilder builder
306
        ) {
307
        return new EqualsGeometryEvaluator(geometry, projection, featureType, geomName,builder);
264 308
    }    
265 309
    
266
    public Evaluator equals(Geometry geometry,
267
        IProjection projection, 
268
        FeatureStore store) {
310
    public Evaluator equals(    
311
            Geometry geometry,
312
            IProjection projection, 
313
            FeatureStore store
314
        ) {
269 315
        try {
270 316
            FeatureType featureType = store.getDefaultFeatureType();
271 317
            String geomName = featureType.getDefaultGeometryAttributeName();
272 318
            ExpressionBuilder builder = store.createExpressionBuilder();
273
            return equals(geometry, projection, featureType, geomName,builder);
319
            return this.equals(geometry, projection, featureType, geomName,builder);
274 320
        } catch (DataException ex) {
275 321
            throw new RuntimeException("Can't create equals evaluator.",ex);
276 322
        }
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/WithinGeometryEvaluator.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.ICoordTrans;
27 26
import org.cresques.cts.IProjection;
27
import org.gvsig.fmap.dal.ExpressionBuilder;
28 28
import org.gvsig.fmap.dal.feature.Feature;
29 29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
30 30
import org.gvsig.fmap.dal.feature.FeatureType;
......
32 32
import org.gvsig.tools.evaluator.AbstractEvaluator;
33 33
import org.gvsig.tools.evaluator.EvaluatorData;
34 34
import org.gvsig.tools.evaluator.EvaluatorException;
35
/**
36
 *
37
 * @author Vicente Caballero Navarro
38
 *
39
 */
35

  
40 36
public class WithinGeometryEvaluator extends AbstractEvaluator {
41 37

  
42
	private String geomName;
43
	private Geometry geometry;
44
	private Geometry geometryTrans;
45
	private String srs;
46
	private boolean isDefault;
38
    private final String geomName;
39
    private final Geometry geometry;
40
    private final Geometry geometryTrans;
41
    private final boolean isDefault;
42
    private final ExpressionBuilder builder;
43
    private final IProjection projection;
47 44

  
48
	WithinGeometryEvaluator(Geometry geometry,
49
			IProjection envelopeProjection, FeatureType featureType,
50
			String geomName) {
51
		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
52
				.get(geomName);
53
		this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
54
				geomName);
55
		this.geometry = geometry;
56
		this.geometryTrans = geometry.cloneGeometry();
57
		this.srs = envelopeProjection.getAbrev();
58
		
59
		IProjection fad_proj = fad.getSRS();
60
		ICoordTrans ct = null;
61
		
62
		if (fad_proj != null && !fad_proj.equals(envelopeProjection)) {
63
		    ct = envelopeProjection.getCT(fad_proj);
64
		}
65
		
66
		if (ct != null) {
67
			geometryTrans.reProject(ct);
68
		}
69
		this.geomName = geomName;
45
    WithinGeometryEvaluator(
46
            Geometry geometry,
47
            IProjection projection,
48
            FeatureType featureType,
49
            String geomName,
50
            ExpressionBuilder builder
51
        ) {
52
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
53
                .get(geomName);
54
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
55
                geomName);
56
        this.geometry = geometry;
57
        this.geometryTrans = geometry.cloneGeometry();
58
        this.projection = projection;
59
        this.builder = builder;
70 60

  
71
		this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
61
        IProjection fad_proj = fad.getSRS();
62
        ICoordTrans ct = null;
72 63

  
73
	}
64
        if (fad_proj != null && !fad_proj.equals(projection)) {
65
            ct = projection.getCT(fad_proj);
66
        }
74 67

  
75
	public Object evaluate(EvaluatorData data) throws EvaluatorException {
76
		try {
77
			Geometry geom = null;
78
			if (isDefault) {
79
				Feature feature = (Feature) data.getContextValue("feature");
80
				geom =feature.getDefaultGeometry();
68
        if (ct != null) {
69
            geometryTrans.reProject(ct);
70
        }
71
        this.geomName = geomName;
81 72

  
82
			} else {
83
				geom = (Geometry) data.getDataValue(geomName);
84
			}
85
                        if ( geom == null ) {
86
                            return Boolean.FALSE;
87
                        }
88
			return new Boolean(geometryTrans.within(geom));
73
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
89 74

  
90
		} catch (Exception e) {
91
			throw new EvaluatorException(e);
92
		}
93
	}
75
    }
94 76

  
95
	public String getName() {
96
		return "within with geometry";
97
	}
77
    @Override
78
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
79
        try {
80
            Geometry geom;
81
            if (isDefault) {
82
                Feature feature = (Feature) data.getContextValue("feature");
83
                geom = feature.getDefaultGeometry();
98 84

  
99
	public String getSQL() {
100
		return " ST_within(ST_GeomFromText('" + geometry.toString() + "', " + "'"
101
				+ srs + "'" + "), " + geomName + ") ";
102
	}
85
            } else {
86
                geom = (Geometry) data.getDataValue(geomName);
87
            }
88
            if (geom == null) {
89
                return false;
90
            }
91
            return geometryTrans.within(geom);
103 92

  
93
        } catch (Exception e) {
94
            throw new EvaluatorException(e);
95
        }
96
    }
97

  
98
    @Override
99
    public String getName() {
100
        return "within with geometry";
101
    }
102

  
103
    @Override
104
    public String getSQL() {
105
        return this.builder.set(
106
                builder.ST_Within(
107
                        builder.geometry(geometry, projection),
108
                        builder.column(geomName)
109
                )
110
        ).toString();
111
    }
104 112
}
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/OutGeometryEvaluator.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.ICoordTrans;
27 26
import org.cresques.cts.IProjection;
27
import org.gvsig.fmap.dal.ExpressionBuilder;
28 28
import org.gvsig.fmap.dal.feature.Feature;
29 29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
30 30
import org.gvsig.fmap.dal.feature.FeatureType;
......
32 32
import org.gvsig.tools.evaluator.AbstractEvaluator;
33 33
import org.gvsig.tools.evaluator.EvaluatorData;
34 34
import org.gvsig.tools.evaluator.EvaluatorException;
35
/**
36
 *
37
 * @author Vicente Caballero Navarro
38
 *
39
 */
35

  
40 36
public class OutGeometryEvaluator extends AbstractEvaluator {
41 37

  
42
	private String geomName;
43
	private Geometry geometry;
44
	private Geometry geometryTrans;
45
	private String srs;
46
	private boolean isDefault;
38
    private final String geomName;
39
    private final Geometry geometry;
40
    private final Geometry geometryTrans;
41
    private final boolean isDefault;
42
    private final ExpressionBuilder builder;
43
    private final IProjection projection;
47 44

  
48
	OutGeometryEvaluator(Geometry geometry,
49
			IProjection envelopeProjection, FeatureType featureType,
50
			String geomName) {
51
		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
52
				.get(geomName);
53
		this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
54
				geomName);
55
		this.geometry = geometry;
56
		this.geometryTrans = geometry.cloneGeometry();
57
		this.srs = envelopeProjection.getAbrev();
58
		
59
		IProjection fad_proj = fad.getSRS();
60
		ICoordTrans ct = null;
61
		
62
		if (fad_proj != null && !fad_proj.equals(envelopeProjection)) {
63
		    ct = envelopeProjection.getCT(fad_proj);
64
		}
45
    OutGeometryEvaluator(
46
            Geometry geometry,
47
            IProjection envelopeProjection, 
48
            FeatureType featureType,
49
            String geomName,
50
            ExpressionBuilder builder
51
        ) {
52
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
53
                .get(geomName);
54
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
55
        this.geometry = geometry;
56
        this.geometryTrans = geometry.cloneGeometry();
57
        this.projection = envelopeProjection;
58
        this.builder = builder;
65 59

  
66
		if (ct != null) {
67
			geometryTrans.reProject(ct);
68
		}
69
		this.geomName = geomName;
60
        IProjection fad_proj = fad.getSRS();
61
        ICoordTrans ct = null;
70 62

  
71
		this.getFieldsInfo().addFieldValue(geomName);
63
        if (fad_proj != null && !fad_proj.equals(envelopeProjection)) {
64
            ct = envelopeProjection.getCT(fad_proj);
65
        }
72 66

  
73
	}
67
        if (ct != null) {
68
            geometryTrans.reProject(ct);
69
        }
70
        this.geomName = geomName;
74 71

  
75
	public Object evaluate(EvaluatorData data) throws EvaluatorException {
76
		try {
77
			Geometry geom = null;
78
			if (isDefault) {
79
				Feature feature = (Feature) data.getContextValue("feature");
80
				geom = feature.getDefaultGeometry();
72
        this.getFieldsInfo().addFieldValue(geomName);
81 73

  
82
			} else {
83
				geom = (Geometry) data.getDataValue(geomName);
84
			}
85
                        if ( geom == null ) {
86
                            return Boolean.FALSE;
87
                        }
88
			return new Boolean(!geometryTrans.contains(geom) && !geometryTrans.intersects(geom));
74
    }
89 75

  
90
		} catch (Exception e) {
91
			throw new EvaluatorException(e);
92
		}
93
	}
76
    @Override
77
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
78
        try {
79
            Geometry geom;
80
            if (isDefault) {
81
                Feature feature = (Feature) data.getContextValue("feature");
82
                geom = feature.getDefaultGeometry();
94 83

  
95
	public String getName() {
96
		return "out of geometry";
97
	}
84
            } else {
85
                geom = (Geometry) data.getDataValue(geomName);
86
            }
87
            if (geom == null) {
88
                return Boolean.FALSE;
89
            }
90
            return !geometryTrans.contains(geom) && !geometryTrans.intersects(geom);
98 91

  
99
	public String getSQL() {
100
		return " not ST_contains(ST_GeomFromText('" + geometry.toString() + "', " + "'"
101
				+ srs + "'" + "), " + geomName + ") ";
102
	}
92
        } catch (Exception e) {
93
            throw new EvaluatorException(e);
94
        }
95
    }
103 96

  
97
    @Override
98
    public String getName() {
99
        return "out of geometry";
100
    }
101

  
102
    @Override
103
    public String getSQL() {
104
        return this.builder.set(
105
                builder.not(
106
                    builder.ST_Contains(
107
                            builder.geometry(geometry, projection),
108
                            builder.column(geomName)
109
                    )
110
                )
111
        ).toString();
112
    }
113

  
104 114
}
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/TouchesGeometryEvaluator.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.ICoordTrans;
27 26
import org.cresques.cts.IProjection;
27
import org.gvsig.fmap.dal.ExpressionBuilder;
28 28
import org.gvsig.fmap.dal.feature.Feature;
29 29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
30 30
import org.gvsig.fmap.dal.feature.FeatureType;
......
32 32
import org.gvsig.tools.evaluator.AbstractEvaluator;
33 33
import org.gvsig.tools.evaluator.EvaluatorData;
34 34
import org.gvsig.tools.evaluator.EvaluatorException;
35
/**
36
 *
37
 * @author Vicente Caballero Navarro
38
 *
39
 */
35

  
40 36
public class TouchesGeometryEvaluator extends AbstractEvaluator {
41 37

  
42
	private String geomName;
43
	private Geometry geometry;
44
	private Geometry geometryTrans;
45
	private String srs;
46
	private boolean isDefault;
38
    private final String geomName;
39
    private final Geometry geometry;
40
    private final Geometry geometryTrans;
41
    private final boolean isDefault;
42
    private final ExpressionBuilder builder;
43
    private final IProjection projection;
47 44

  
48
	TouchesGeometryEvaluator(Geometry geometry,
49
			IProjection envelopeProjection, FeatureType featureType,
50
			String geomName) {
51
		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
52
				.get(geomName);
53
		this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
54
				geomName);
55
		this.geometry = geometry;
56
		this.geometryTrans = geometry.cloneGeometry();
57
		this.srs = envelopeProjection.getAbrev();
58
		
59
		IProjection fad_proj = fad.getSRS();
60
		ICoordTrans ct = null;
61
		
62
		if (fad_proj != null && !fad_proj.equals(envelopeProjection)) {
63
		    ct = envelopeProjection.getCT(fad_proj);
64
		}
65
		
66
		if (ct != null) {
67
			geometryTrans.reProject(ct);
68
		}
69
		this.geomName = geomName;
45
    TouchesGeometryEvaluator(Geometry geometry,
46
            IProjection projection,
47
            FeatureType featureType,
48
            String geomName,
49
            ExpressionBuilder builder
50
        ) {
51
        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
52
                .get(geomName);
53
        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
54
                geomName);
55
        this.geometry = geometry;
56
        this.geometryTrans = geometry.cloneGeometry();
57
        this.projection = projection;
58
        this.builder = builder;
70 59

  
71
		this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
60
        IProjection fad_proj = fad.getSRS();
61
        ICoordTrans ct = null;
72 62

  
73
	}
63
        if (fad_proj != null && !fad_proj.equals(projection)) {
64
            ct = projection.getCT(fad_proj);
65
        }
74 66

  
75
	public Object evaluate(EvaluatorData data) throws EvaluatorException {
76
		try {
77
			Geometry geom = null; 
78
			if (isDefault) {
79
				Feature feature = (Feature) data.getContextValue("feature");
80
				geom = feature.getDefaultGeometry();
67
        if (ct != null) {
68
            geometryTrans.reProject(ct);
69
        }
70
        this.geomName = geomName;
81 71

  
82
			} else {
83
				geom = (Geometry) data.getDataValue(geomName);
84
			}
85
                        if ( geom == null ) {
86
                            return Boolean.FALSE;
87
                        }
88
			return new Boolean(geometryTrans.touches(geom));
72
        this.getFieldsInfo().addMatchFieldValue(geomName, geometryTrans);
89 73

  
90
		} catch (Exception e) {
91
			throw new EvaluatorException(e);
92
		}
93
	}
74
    }
94 75

  
95
	public String getName() {
96
		return "touches with geometry";
97
	}
76
    @Override
77
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
78
        try {
79
            Geometry geom;
80
            if (isDefault) {
81
                Feature feature = (Feature) data.getContextValue("feature");
82
                geom = feature.getDefaultGeometry();
98 83

  
99
	public String getSQL() {
100
		return " ST_touches(ST_GeomFromText('" + geometry.toString() + "', " + "'"
101
				+ srs + "'" + "), " + geomName + ") ";
102
	}
84
            } else {
85
                geom = (Geometry) data.getDataValue(geomName);
86
            }
87
            if (geom == null) {
88
                return Boolean.FALSE;
89
            }
90
            return geometryTrans.touches(geom);
103 91

  
92
        } catch (Exception e) {
93
            throw new EvaluatorException(e);
94
        }
95
    }
96

  
97
    @Override
98
    public String getName() {
99
        return "touches with geometry";
100
    }
101

  
102
    @Override
103
    public String getSQL() {
104
        return this.builder.set(
105
                builder.ST_Touches(
106
                        builder.geometry(geometry, projection),
107
                        builder.column(geomName)
108
                )
109
        ).toString();
110
    }
104 111
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff