Revision 4414

View differences:

org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/TopologyImplLibrary.java
31 31
import org.gvsig.topology.lib.api.TopologyLibrary;
32 32
import org.gvsig.topology.lib.api.TopologyLocator;
33 33
import org.gvsig.topology.lib.api.TopologyManager;
34
import org.gvsig.topology.rule.ContainsNullRuleFactory;
35
import org.gvsig.topology.rule.ContainsPointRuleFactory;
36
import org.gvsig.topology.rule.MustBeLargerThanToleranceLineRuleFactory;
37
import org.gvsig.topology.rule.MustNotOverlapPolygonRuleFactory;
34
import org.gvsig.topology.rule.GeometryMustNotBeNullRuleFactory;
35
import org.gvsig.topology.rule.LineMustBeCoveredByBoundaryOfPolygonRuleFactory;
36
import org.gvsig.topology.rule.PolygonContainsPointRuleFactory;
37
import org.gvsig.topology.rule.LineMustBeLargerThanToleranceRuleFactory;
38
import org.gvsig.topology.rule.PolygonMustNotOverlapPolygonRuleFactory;
38 39
import org.gvsig.topology.rule.PointMustBeProperlyInsidePolygonRuleFactory;
40
import org.gvsig.topology.rule.PolygonMustBeCoveredByPolygonRuleFactory;
39 41

  
40 42
/**
41 43
 *
......
59 61

  
60 62
    @Override
61 63
    protected void doPostInitialize() throws LibraryException {
62
        ContainsNullRuleFactory.selfRegister();
63
        ContainsPointRuleFactory.selfRegister();
64
        MustBeLargerThanToleranceLineRuleFactory.selfRegister();
65
        MustNotOverlapPolygonRuleFactory.selfRegister();
64
        GeometryMustNotBeNullRuleFactory.selfRegister();
65
        LineMustBeCoveredByBoundaryOfPolygonRuleFactory.selfRegister();
66
//        LineMustBeLargerThanToleranceRuleFactory.selfRegister();
66 67
        PointMustBeProperlyInsidePolygonRuleFactory.selfRegister();
68
        PolygonContainsPointRuleFactory.selfRegister();
69
        PolygonMustBeCoveredByPolygonRuleFactory.selfRegister();
70
        PolygonMustNotOverlapPolygonRuleFactory.selfRegister();
67 71
    }
68 72

  
69 73
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsPointRule.java
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.topology.rule;
25

  
26
import org.gvsig.expressionevaluator.Expression;
27
import org.gvsig.expressionevaluator.ExpressionUtils;
28
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
29
import org.gvsig.expressionevaluator.GeometryExpressionUtils;
30
import org.gvsig.fmap.dal.feature.EditableFeature;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureReference;
33
import org.gvsig.fmap.dal.feature.FeatureSet;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.primitive.Point;
37
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.task.SimpleTaskStatus;
39
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
40
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
41
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
42
import org.gvsig.topology.lib.api.TopologyDataSet;
43
import org.gvsig.topology.lib.api.TopologyPlan;
44
import org.gvsig.topology.lib.api.TopologyReport;
45
import org.gvsig.topology.lib.api.TopologyReportLine;
46
import org.gvsig.topology.lib.api.TopologyRule;
47
import org.gvsig.topology.lib.api.TopologyRuleFactory;
48

  
49
/**
50
 *
51
 * @author jjdelcerro
52
 */
53
@SuppressWarnings("UseSpecificCatch")
54
public class ContainsPointRule extends AbstractTopologyRule {
55

  
56
    private class CreateFetureAction extends AbstractTopologyRuleAction {
57

  
58
        public CreateFetureAction() {
59
            super(
60
                    ContainsPointRuleFactory.NAME,
61
                    "CreateFeature",
62
                    "Create Feature",
63
                    "The Create Feature fix creates a new point feature at the centroid of the polygon feature that is causing the error. The point feature that is created is guaranteed to be within the polygon feature."
64
            );
65
        }
66

  
67
        @Override
68
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
69
            try {
70
                Geometry polygon = line.getGeometry();
71
                Point point = polygon.centroid();
72
                if( !polygon.contains(point) ) {
73
                    point = polygon.getInteriorPoint();
74
                }
75
                TopologyDataSet dataSet = rule.getDataSet2();
76

  
77
                EditableFeature feature = dataSet.createNewFeature();
78
                feature.setDefaultGeometry(point);
79
                dataSet.insert(feature);
80

  
81
            } catch (Exception ex) {
82
                throw new ExecuteTopologyRuleActionException(ex);
83
            }
84
        }
85

  
86
    }
87

  
88
    private String geomName;
89
    private Expression expression = null;
90
    private GeometryExpressionBuilder expressionBuilder = null;
91

  
92
    public ContainsPointRule(
93
            TopologyPlan plan,
94
            TopologyRuleFactory factory,
95
            double tolerance,
96
            String dataSet1,
97
            String dataSet2
98
    ) {
99
        super(plan, factory, tolerance, dataSet1, dataSet2);
100

  
101
        this.addAction(new CreateFetureAction());
102
    }
103

  
104
    @Override
105
    protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception {
106
        FeatureSet set = null;
107
        try {
108
            FeatureStore store2 = this.getDataSet2().getFeatureStore();
109
            if (this.expression == null) {
110
                this.expression = ExpressionUtils.createExpression();
111
                this.expressionBuilder = GeometryExpressionUtils.createExpressionBuilder();
112
                this.geomName = store2.getDefaultFeatureType().getDefaultGeometryAttributeName();
113
            }
114
            Geometry polygon = feature1.getDefaultGeometry();
115
            TopologyDataSet theDataSet = this.getDataSet2();
116
            if (theDataSet.getSpatialIndex() != null) {
117
                boolean contains = false;
118
                for (FeatureReference featureReference : theDataSet.query(polygon)) {
119
                    Feature feature2 = featureReference.getFeature();
120
                    Geometry otherPoint = feature2.getDefaultGeometry();
121
                    if( otherPoint!=null && polygon.contains(otherPoint) ) {
122
                        contains = true;
123
                        break;
124
                    }
125
                }
126
                if( !contains ) {
127
                    report.addLine(this,
128
                            this.getDataSet1(),
129
                            this.getDataSet2(),
130
                            polygon,
131
                            polygon,
132
                            feature1.getReference(),
133
                            null,
134
                            false,
135
                            "The polygon is an error because it does not contain a point."
136
                    );
137
                }
138
            } else {
139
                this.expression.setPhrase(
140
                        this.expressionBuilder.ifnull(
141
                                this.expressionBuilder.column(this.geomName),
142
                                this.expressionBuilder.constant(false),
143
                                this.expressionBuilder.ST_Contains(
144
                                        this.expressionBuilder.geometry(polygon),
145
                                        this.expressionBuilder.column(this.geomName)
146
                                )
147
                        ).toString()
148
                );
149
                if (theDataSet.findFirst(this.expression) == null) {
150
                    report.addLine(this,
151
                            this.getDataSet1(),
152
                            this.getDataSet2(),
153
                            polygon,
154
                            polygon,
155
                            feature1.getReference(),
156
                            null,
157
                            false,
158
                            "The polygon is an error because it does not contain a point."
159
                    );
160
                }
161
            }
162
        } catch (Exception ex) {
163
            LOGGER.warn("Can't check feature.", ex);
164
        } finally {
165
            if (set != null) {
166
                set.dispose();
167
            }
168
        }
169
    }
170

  
171
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsNullRule.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.dal.feature.FeatureSet;
28
import org.gvsig.tools.task.SimpleTaskStatus;
29
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
30
import org.gvsig.topology.lib.api.TopologyPlan;
31
import org.gvsig.topology.lib.api.TopologyReport;
32
import org.gvsig.topology.lib.api.TopologyRuleFactory;
33

  
34
/**
35
 *
36
 * @author jjdelcerro
37
 */
38
@SuppressWarnings("UseSpecificCatch")
39
public class ContainsNullRule extends AbstractTopologyRule {
40

  
41
    public ContainsNullRule(
42
            TopologyPlan plan,
43
            TopologyRuleFactory factory,
44
            double tolerance,
45
            String dataSet1,
46
            String dataSet2
47
    ) {
48
        super(plan, factory, tolerance, dataSet1, dataSet2);
49
    }
50

  
51
    @Override
52
    protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception {
53
        FeatureSet set = null;
54
        try {
55
            if ( feature1.getDefaultGeometry()==null ) {
56
                report.addLine(this,
57
                        this.getDataSet1(),
58
                        this.getDataSet2(),
59
                        feature1.getDefaultGeometry(),
60
                        null,
61
                        feature1.getReference(),
62
                        null,
63
                        false,
64
                        "The geometry is null."
65
                );
66
            }
67
        } catch(Exception ex) {
68
            LOGGER.warn("Can't check feature.", ex);
69
        } finally {
70
            if( set!=null ) {
71
                set.dispose();
72
            }
73
        }
74
    }
75

  
76
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/MustNotOverlapPolygonRule.java
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.topology.rule;
25

  
26
import org.gvsig.expressionevaluator.Expression;
27
import org.gvsig.expressionevaluator.ExpressionUtils;
28
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
29
import org.gvsig.expressionevaluator.GeometryExpressionUtils;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.EditableFeature;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.dal.feature.FeatureReference;
34
import org.gvsig.fmap.dal.feature.FeatureSet;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.tools.dynobject.DynObject;
39
import org.gvsig.tools.task.SimpleTaskStatus;
40
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
41
import org.gvsig.topology.lib.api.TopologyDataSet;
42
import org.gvsig.topology.lib.api.TopologyPlan;
43
import org.gvsig.topology.lib.api.TopologyReport;
44
import org.gvsig.topology.lib.api.TopologyReportLine;
45
import org.gvsig.topology.lib.api.TopologyRule;
46
import org.gvsig.topology.lib.api.TopologyRuleFactory;
47
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
48
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
49

  
50
/**
51
 *
52
 * @author jjdelcerro
53
 */
54
@SuppressWarnings("UseSpecificCatch")
55
public class MustNotOverlapPolygonRule extends AbstractTopologyRule {
56

  
57
    private class CreateFetureAction extends AbstractTopologyRuleAction {
58

  
59
        public CreateFetureAction() {
60
            super(
61
                    MustNotOverlapPolygonRuleFactory.NAME,
62
                    "CreateFeature",
63
                    "Create Feature",
64
                    "The Create Feature fix creates a new polygon feature out "
65
                    + "of the error shape and removes the portion of "
66
                    + "overlap from each of the features, causing the "
67
                    + "error to create a planar representation of the "
68
                    + "feature geometry. This fix can be applied to "
69
                    + "one or more selected Must Not Overlap errors."
70
            );
71
        }
72

  
73
        @Override
74
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
75
            try {
76
                Geometry errorGeom = line.getError();
77
                TopologyDataSet dataSet = rule.getDataSet1();
78

  
79
                FeatureReference featRef1 = line.getFeature1();
80
                
81
                Feature feat1 = featRef1.getFeature();
82
                Geometry geom1 = feat1.getDefaultGeometry();
83
                
84
                FeatureReference featRef2 = line.getFeature2();
85
                Feature feat2 = featRef2.getFeature();
86
                Geometry geom2 = feat2.getDefaultGeometry();
87
                
88
                createNewFeature(featRef1, dataSet, errorGeom);
89
                substract(featRef1, geom2, rule.getDataSet1());
90
                substract(featRef2, geom1, rule.getDataSet1());
91

  
92
//                substract(featRef1, errorGeom, rule.getDataSet1());
93
//                substract(featRef2, errorGeom, rule.getDataSet1());
94

  
95
            } catch (Exception ex) {
96
                throw new ExecuteTopologyRuleActionException(ex);
97
            }
98
        }
99

  
100
    }
101

  
102
    private class SubtractAction extends AbstractTopologyRuleAction {
103

  
104
        public SubtractAction() {
105
            super(
106
                    MustNotOverlapPolygonRuleFactory.NAME,
107
                    "Subtract",
108
                    "Subtract",
109
                    "The Subtract fix removes the overlapping portion of "
110
                    + "geometry from each feature that is causing the "
111
                    + "error and leaves a gap or void in its place. "
112
                    + "This fix can be applied to one or more selected "
113
                    + "Must Not Overlap errors."
114
            );
115
        }
116

  
117
        @Override
118
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
119
            try {
120
                Geometry errorGeom = line.getError();
121
                TopologyDataSet dataSet = rule.getDataSet1();
122

  
123
                FeatureReference featRef1 = line.getFeature1();
124
                
125
                Feature feat1 = featRef1.getFeature();
126
                Geometry geom1 = feat1.getDefaultGeometry();
127
                
128
                FeatureReference featRef2 = line.getFeature2();
129
                Feature feat2 = featRef2.getFeature();
130
                Geometry geom2 = feat2.getDefaultGeometry();
131
                
132
                substract(featRef1, geom2, rule.getDataSet1());
133
                substract(featRef2, geom1, rule.getDataSet1());
134

  
135
                
136
//                Geometry errorGeom = line.getError();
137
//                
138
//                FeatureReference featRef1 = line.getFeature1();
139
//                substract(featRef1, errorGeom, rule.getDataSet1());
140
//                
141
//                FeatureReference featRef2 = line.getFeature2();
142
//                substract(featRef2, errorGeom, rule.getDataSet1());
143
                
144
//                for (FeatureReference reference : dataSet.query(errorGeom)) {
145
//                    Feature initialFeature = reference.getFeature();
146
//                    Geometry initialFeatureGeom = initialFeature.getDefaultGeometry();
147
////                    initialFeature1.getEditable();
148
//                    if (initialFeatureGeom.intersects(errorGeom)) {
149
//                        Geometry targetFeatureGeom = initialFeatureGeom.difference(errorGeom);
150
//                        EditableFeature targetFeature = dataSet.createNewFeature();
151
//                        targetFeature.copyFrom(initialFeature);
152
//                        targetFeature.setDefaultGeometry(targetFeatureGeom);
153
//                        dataSet.insert(targetFeature);
154
//                        dataSet.delete(reference);
155
//                    }      
156
//                } 
157
            } catch (Exception ex) {
158
                throw new ExecuteTopologyRuleActionException(ex);
159
            }
160
        }
161

  
162
    }
163

  
164
    private class MergeAction extends AbstractTopologyRuleAction {
165

  
166
        public MergeAction() {
167
            super(
168
                    MustNotOverlapPolygonRuleFactory.NAME,
169
                    "Merge",
170
                    "Merge",
171
                    "The Merge fix adds the portion of overlap from one feature "
172
                    + "and subtracts it from the others that are "
173
                    + "violating the rule. You need to pick the feature "
174
                    + "that receives the portion of overlap using the "
175
                    + "Merge dialog box. This fix can be applied to one "
176
                    + "Must Not Overlap error only."
177
            );
178
        }
179

  
180
        @Override
181
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
182
            try {
183
                Geometry errorGeom = line.getError();
184
                TopologyDataSet dataSet = rule.getDataSet1();
185

  
186
                FeatureReference featRef1 = line.getFeature1();
187
                Feature feat1 = featRef1.getFeature();
188
                Geometry geom1 = feat1.getDefaultGeometry();
189
                
190
                FeatureReference featRef2 = line.getFeature2();
191
                
192
                substract(featRef2, geom1, rule.getDataSet1());
193

  
194
                
195
                
196
                
197
                
198
                
199
//                Geometry errorGeom = line.getError();
200
//                
201
//                FeatureReference featRef2 = line.getFeature2();
202
//                substract(featRef2, errorGeom, rule.getDataSet1());
203
                
204
                
205
//                TopologyDataSet dataSet = rule.getDataSet1();
206
//                
207
//                Feature initialFeature1 = line.getFeature1().getFeature();
208
//                EditableFeature targetFeature1 = dataSet.createNewFeature();
209
//                targetFeature1.copyFrom(initialFeature1);
210
//                
211
//                Feature initialFeature2 = line.getFeature2().getFeature();
212
//                EditableFeature targetFeature2 = dataSet.createNewFeature();
213
//                targetFeature2.copyFrom(initialFeature2);
214
//                
215
//                Geometry initialFeature1Geom = initialFeature1.getDefaultGeometry();
216
////                Geometry targetFeature1Geom = initialFeature1Geom.union(errorGeom);
217
//                
218
//                Geometry initialFeature2Geom = initialFeature2.getDefaultGeometry();
219
//                Geometry targetFeature2Geom = initialFeature2Geom.difference(initialFeature1Geom);
220
//                
221
////                targetFeature1.setDefaultGeometry(targetFeature1Geom);
222
//                targetFeature2.setDefaultGeometry(targetFeature2Geom);
223
//                
224
////                dataSet.insert(targetFeature1);
225
//                dataSet.insert(targetFeature2);
226
//                
227
//                dataSet.delete(line.getFeature1());
228
//                dataSet.delete(line.getFeature2());
229
            
230
            } catch (Exception ex) {
231
                throw new ExecuteTopologyRuleActionException(ex);
232
            }
233
        }
234

  
235
    }
236

  
237
    private String geomName;
238
    private Expression expression = null;
239
    private GeometryExpressionBuilder expressionBuilder = null;
240

  
241
    public MustNotOverlapPolygonRule(
242
            TopologyPlan plan,
243
            TopologyRuleFactory factory,
244
            double tolerance,
245
            String dataSet1
246
    ) {
247
        super(plan, factory, tolerance, dataSet1);
248
        this.addAction(new CreateFetureAction());
249
        this.addAction(new MergeAction());
250
        this.addAction(new SubtractAction());
251
    }
252

  
253
    @Override
254
    protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception {
255
        try {
256
            if (this.expression == null) {
257
                this.expression = ExpressionUtils.createExpression();
258
                this.expressionBuilder = GeometryExpressionUtils.createExpressionBuilder();
259
                this.geomName = feature1.getType().getDefaultGeometryAttributeName();
260
            }
261
            Geometry polygon = feature1.getDefaultGeometry();
262
            if( polygon==null ) {
263
                return;
264
            }
265
            TopologyDataSet theDataSet = this.getDataSet1();
266
            if (theDataSet.getSpatialIndex() != null) {
267
                for (FeatureReference otherReference : theDataSet.query(polygon)) {
268
                    if (otherReference.equals(feature1.getReference())) {
269
                        continue;
270
                    }
271
                    Feature otherFeature = otherReference.getFeature();
272
                    Geometry otherPolygon = otherFeature.getDefaultGeometry();
273
                    double halfTolerance = this.getTolerance()/2;
274
                    if (otherPolygon!=null && polygon.buffer(-halfTolerance).overlaps(otherPolygon.buffer(-halfTolerance))) {;
275
                        Geometry error = polygon.intersection(otherPolygon);
276
                        report.addLine(this,
277
                                theDataSet,
278
                                null,
279
                                polygon,
280
                                error,
281
                                feature1.getReference(),
282
                                otherReference,
283
                                false,
284
                                "The polygon overlay with others."
285
                        );
286
//                        break;
287
                    }
288
                }
289
            } else {
290
                this.expression.setPhrase(
291
                        this.expressionBuilder.ifnull(
292
                                this.expressionBuilder.column(this.geomName),
293
                                this.expressionBuilder.constant(false),
294
                                this.expressionBuilder.ST_Overlaps(
295
                                        this.expressionBuilder.column(this.geomName),
296
                                        this.expressionBuilder.geometry(polygon)
297
                                )
298
                        ).toString()
299
                );
300
                FeatureSet features = theDataSet.getFeatureStore().getFeatureSet(this.expression);
301
                for (Feature feature : features) {
302
                    if ( feature != null) {
303
                        Geometry otherPolygon = feature.getDefaultGeometry();
304
                        double halfTolerance = this.getTolerance()/2;
305
                        if (otherPolygon!=null && polygon.buffer(-halfTolerance).overlaps(otherPolygon.buffer(-halfTolerance))) {
306
                            Geometry error = polygon.intersection(otherPolygon);
307
                            report.addLine(this,
308
                                    theDataSet,
309
                                    null,
310
                                    polygon,
311
                                    error,
312
                                    feature1.getReference(),
313
                                    feature.getReference(),
314
                                    false,
315
                                    "The polygon overlay with others."
316
                            );
317
                        }
318
                    }
319
                }
320
            }
321
        } catch (Exception ex) {
322
            LOGGER.warn("Can't check feature.", ex);
323
        } finally {
324
        }
325
    }
326
    
327
    private void substract(FeatureReference featRef, Geometry geomToSubstract, TopologyDataSet dataSet) throws DataException, GeometryOperationException, GeometryOperationNotSupportedException {
328
        Feature feat = featRef.getFeature();
329
        EditableFeature editFeat = feat.getEditable();
330
        Geometry geom = editFeat.getDefaultGeometry();
331
        Geometry diff = geom.difference(geomToSubstract);
332
        editFeat.setDefaultGeometry(diff);
333
        dataSet.update(editFeat);
334
    }
335

  
336
    private void createNewFeature(FeatureReference featRef, TopologyDataSet dataSet, Geometry errorGeom) throws DataException {
337
        Feature featureToCopyFrom = featRef.getFeature();
338
        EditableFeature targetFeature = dataSet.createNewFeature();
339
        targetFeature.copyFrom(featureToCopyFrom);
340
        targetFeature.setDefaultGeometry(errorGeom);
341
        dataSet.insert(targetFeature);
342
     }
343

  
344
}
345

  
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/MustBeLargerThanToleranceLineRule.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.tools.dynobject.DynObject;
29
import org.gvsig.tools.task.SimpleTaskStatus;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
31
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
32
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
33
import org.gvsig.topology.lib.api.TopologyDataSet;
34
import org.gvsig.topology.lib.api.TopologyPlan;
35
import org.gvsig.topology.lib.api.TopologyReport;
36
import org.gvsig.topology.lib.api.TopologyReportLine;
37
import org.gvsig.topology.lib.api.TopologyRule;
38
import org.gvsig.topology.lib.api.TopologyRuleFactory;
39

  
40
/**
41
 *
42
 * @author jjdelcerro
43
 */
44
@SuppressWarnings("UseSpecificCatch")
45
public class MustBeLargerThanToleranceLineRule extends AbstractTopologyRule {
46

  
47
    private class DeleteAction extends AbstractTopologyRuleAction {
48

  
49
        public DeleteAction() {
50
            super(
51
                MustBeLargerThanToleranceLineRuleFactory.NAME, 
52
                "delete", 
53
                "Delete", 
54
                "Removes line features that would collapse during the validate process based on the topology's tolerance."
55
            );
56
        }
57
        
58
        @Override
59
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
60
            try {
61
                TopologyDataSet dataset = line.getDataSet1();
62
                dataset.delete(line.getFeature1());
63
            } catch (Exception ex) {
64
                throw new ExecuteTopologyRuleActionException(ex);
65
            }
66
        }
67
        
68
    } 
69
    
70
    public MustBeLargerThanToleranceLineRule( 
71
            TopologyPlan plan,
72
            TopologyRuleFactory factory,
73
            double tolerance,
74
            String dataSet1,
75
            String dataSet2
76

  
77
    ) {
78
        super(plan, factory, tolerance, dataSet1, dataSet2);
79
        this.addAction(new DeleteAction());
80
    }
81
    
82
    @Override
83
    public void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature) throws Exception {
84
        Geometry geom = feature.getDefaultGeometry();
85
        if( geom.perimeter()<this.getTolerance() ) {
86
            report.addLine(this, this.getDataSet1(), null,
87
                    geom, null, feature.getReference(), null, false, 
88
                    "The length of the line is less than the specified tolerance"
89
            );
90
        }
91
    }
92

  
93

  
94
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsPointRuleFactory.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
28
import org.gvsig.topology.lib.api.TopologyLocator;
29
import org.gvsig.topology.lib.api.TopologyManager;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
31
import org.gvsig.topology.lib.api.TopologyPlan;
32
import org.gvsig.topology.lib.api.TopologyRule;
33

  
34
/**
35
 *
36
 * @author jjdelcerro
37
 */
38
@SuppressWarnings("UseSpecificCatch")
39
public class ContainsPointRuleFactory extends AbstractTopologyRuleFactory {
40
    
41
    public static final String NAME = "ContainsPoint";
42
    
43
    public ContainsPointRuleFactory() {
44
        super(
45
                NAME, 
46
                "Contains Point", 
47
                "Requires that a polygon in one dataset contain at least one point from another dataset. Points must be within the polygon, not on the boundary. ", 
48
                new ListBuilder<Integer>()
49
                        .add(Geometry.TYPES.SURFACE)
50
                        .add(Geometry.TYPES.MULTISURFACE)
51
                        .asList(),
52
                new ListBuilder<Integer>()
53
                        .add(Geometry.TYPES.POINT)
54
                        .asList()
55
        );
56
    }
57
    
58
    @Override
59
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
60
        TopologyRule rule = new ContainsPointRule(plan, this, tolerance, dataSet1, dataSet2);
61
        return rule;
62
    }    
63

  
64
    public static void selfRegister() {
65
        try {
66
            TopologyManager manager = TopologyLocator.getTopologyManager();
67
            manager.addRuleFactories(new ContainsPointRuleFactory());
68
        } catch(Exception ex) {
69
            LOGGER.warn("Can't register topology rule from ContainsPointRuleFactory.", ex);
70
        }
71
    }
72
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsNullRuleFactory.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
28
import org.gvsig.topology.lib.api.TopologyLocator;
29
import org.gvsig.topology.lib.api.TopologyManager;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
31
import org.gvsig.topology.lib.api.TopologyPlan;
32
import org.gvsig.topology.lib.api.TopologyRule;
33

  
34
/**
35
 *
36
 * @author jjdelcerro
37
 */
38
@SuppressWarnings("UseSpecificCatch")
39
public class ContainsNullRuleFactory extends AbstractTopologyRuleFactory {
40
    
41
    public static final String NAME = "ContainsNull";
42
    
43
    public ContainsNullRuleFactory() {
44
        super(
45
                NAME, 
46
                "Contains Null", 
47
                "Requires that no geometry has a null value", 
48
                new ListBuilder<Integer>()
49
                        .add(Geometry.TYPES.GEOMETRY)
50
                        .asList(),
51
                null
52
        );
53
    }
54
    
55
    @Override
56
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
57
        TopologyRule rule = new ContainsNullRule(plan, this, tolerance, dataSet1, dataSet2);
58
        return rule;
59
    }    
60

  
61

  
62
    public static void selfRegister() {
63
        try {
64
            TopologyManager manager = TopologyLocator.getTopologyManager();
65
            manager.addRuleFactories(new ContainsNullRuleFactory());
66
        } catch(Exception ex) {
67
            LOGGER.warn("Can't register topology rule from ContainsNullRuleFactory.", ex);
68
        }
69
    }
70
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/MustNotOverlapPolygonRuleFactory.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
28
import org.gvsig.topology.lib.api.TopologyLocator;
29
import org.gvsig.topology.lib.api.TopologyManager;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
31
import org.gvsig.topology.lib.api.TopologyPlan;
32
import org.gvsig.topology.lib.api.TopologyRule;
33

  
34
/**
35
 *
36
 * @author jjdelcerro
37
 */
38
@SuppressWarnings("UseSpecificCatch")
39
public class MustNotOverlapPolygonRuleFactory extends AbstractTopologyRuleFactory {
40

  
41
    public static final String NAME = "MustNotOverlapPolygon";
42
    
43
    public MustNotOverlapPolygonRuleFactory() {
44
        super(
45
                NAME, 
46
                "Must Not Overlap", 
47
                "Requires that the interior of polygons in the dataset not overlap. The polygons can share edges or vertices. This rule is used when an area cannot belong to two or more polygons. It is useful for modeling administrative boundaries, such as ZIP Codes or voting districts, and mutually exclusive area classifications, such as land cover or landform type.", 
48
                new ListBuilder<Integer>()
49
                        .add(Geometry.TYPES.SURFACE)
50
                        .add(Geometry.TYPES.MULTISURFACE)
51
                        .asList()
52
                
53
        );
54
    }
55
    
56
    @Override
57
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
58
        TopologyRule rule = new MustNotOverlapPolygonRule(plan, this, tolerance, dataSet1);
59
        return rule;
60
    }    
61

  
62
    public static void selfRegister() {
63
        try {
64
            TopologyManager manager = TopologyLocator.getTopologyManager();
65
            manager.addRuleFactories(new MustNotOverlapPolygonRuleFactory());
66
        } catch(Exception ex) {
67
            LOGGER.warn("Can't register topology rule from MustNotOverlapPolygonRuleFactory.", ex);
68
        }
69
    }
70
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/MustBeLargerThanToleranceLineRuleFactory.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
28
import org.gvsig.topology.lib.api.TopologyLocator;
29
import org.gvsig.topology.lib.api.TopologyManager;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
31
import org.gvsig.topology.lib.api.TopologyPlan;
32
import org.gvsig.topology.lib.api.TopologyRule;
33

  
34
/**
35
 *
36
 * @author jjdelcerro
37
 */
38
@SuppressWarnings("UseSpecificCatch")
39
public class MustBeLargerThanToleranceLineRuleFactory extends AbstractTopologyRuleFactory {
40

  
41
    public static final String NAME = "MustBeLargerThanToleranceLine";
42
    
43
    public MustBeLargerThanToleranceLineRuleFactory() {
44
        super(
45
                NAME, 
46
                "Must Be Larger Than Tolerance", 
47
                "Requires that a feature does not collapse during a validate process. This rule is mandatory for a topology and applies to all line feature classes. In instances where this rule is violated, the original geometry is left unchanged", 
48
                new ListBuilder<Integer>()
49
                        .add(Geometry.TYPES.CURVE)
50
                        .asList()
51
        );
52
    }
53
    
54
    @Override
55
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
56
        TopologyRule rule = new MustBeLargerThanToleranceLineRule(plan, this, tolerance, dataSet1, dataSet2);
57
        return rule;
58
    }
59
    
60
    public static void selfRegister() {
61
        try {
62
            TopologyManager manager = TopologyLocator.getTopologyManager();
63
            manager.addRuleFactories(new MustBeLargerThanToleranceLineRuleFactory());
64
        } catch(Exception ex) {
65
            LOGGER.warn("Can't register topology rule from MustBeLargerThanToleranceLineRuleFactory.", ex);
66
        }
67
    }
68
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/LineMustBeLargerThanToleranceRule.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.tools.dynobject.DynObject;
29
import org.gvsig.tools.task.SimpleTaskStatus;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
31
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
32
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
33
import org.gvsig.topology.lib.api.TopologyDataSet;
34
import org.gvsig.topology.lib.api.TopologyPlan;
35
import org.gvsig.topology.lib.api.TopologyReport;
36
import org.gvsig.topology.lib.api.TopologyReportLine;
37
import org.gvsig.topology.lib.api.TopologyRule;
38
import org.gvsig.topology.lib.api.TopologyRuleFactory;
39

  
40
/**
41
 *
42
 * @author jjdelcerro
43
 */
44
@SuppressWarnings("UseSpecificCatch")
45
public class LineMustBeLargerThanToleranceRule extends AbstractTopologyRule {
46

  
47
    private class DeleteAction extends AbstractTopologyRuleAction {
48

  
49
        public DeleteAction() {
50
            super(
51
                LineMustBeLargerThanToleranceRuleFactory.NAME, 
52
                "delete", 
53
                "Delete", 
54
                "Removes line features that would collapse during the validate process based on the topology's tolerance."
55
            );
56
        }
57
        
58
        @Override
59
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
60
            try {
61
                TopologyDataSet dataset = line.getDataSet1();
62
                dataset.delete(line.getFeature1());
63
            } catch (Exception ex) {
64
                throw new ExecuteTopologyRuleActionException(ex);
65
            }
66
        }
67
        
68
    } 
69
    
70
    public LineMustBeLargerThanToleranceRule( 
71
            TopologyPlan plan,
72
            TopologyRuleFactory factory,
73
            double tolerance,
74
            String dataSet1,
75
            String dataSet2
76

  
77
    ) {
78
        super(plan, factory, tolerance, dataSet1, dataSet2);
79
        this.addAction(new DeleteAction());
80
    }
81
    
82
    @Override
83
    public void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature) throws Exception {
84
        Geometry geom = feature.getDefaultGeometry();
85
        if( geom.perimeter()<this.getTolerance() ) {
86
            report.addLine(this, this.getDataSet1(), null,
87
                    geom, null, feature.getReference(), null, false, 
88
                    "The length of the line is less than the specified tolerance"
89
            );
90
        }
91
    }
92

  
93

  
94
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/GeometryMustNotBeNullRuleFactory.java
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.topology.rule;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
28
import org.gvsig.topology.lib.api.TopologyLocator;
29
import org.gvsig.topology.lib.api.TopologyManager;
30
import org.gvsig.topology.lib.api.TopologyPlan;
31
import org.gvsig.topology.lib.api.TopologyRule;
32
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
33

  
34
/**
35
 *
36
 * @author jjdelcerro
37
 */
38
@SuppressWarnings("UseSpecificCatch")
39
public class GeometryMustNotBeNullRuleFactory extends AbstractTopologyRuleFactory {
40
    
41
    public static final String NAME = "GeometryMustNotBeNull";
42
    
43
    public GeometryMustNotBeNullRuleFactory() {
44
        super(
45
                NAME, 
46
                "Geometry must not be null", 
47
                "Requires that geometries are not null", 
48
                new ListBuilder<Integer>()
49
                        .add(Geometry.TYPES.GEOMETRY)
50
                        .asList(),
51
                null
52
        );
53
    }
54
    
55
    @Override
56
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
57
        TopologyRule rule = new GeometryMustNotBeNullRule(plan, this, tolerance, dataSet1, dataSet2);
58
        return rule;
59
    }    
60

  
61

  
62
    public static void selfRegister() {
63
        try {
64
            TopologyManager manager = TopologyLocator.getTopologyManager();
65
            manager.addRuleFactories(new GeometryMustNotBeNullRuleFactory());
66
        } catch(Exception ex) {
67
            LOGGER.warn("Can't register topology rule from GeometryMustNotBeNullRuleFactory.", ex);
68
        }
69
    }
70
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/PolygonContainsPointRule.java
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.topology.rule;
25

  
26
import org.gvsig.expressionevaluator.Expression;
27
import org.gvsig.expressionevaluator.ExpressionUtils;
28
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
29
import org.gvsig.expressionevaluator.GeometryExpressionUtils;
30
import org.gvsig.fmap.dal.feature.EditableFeature;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureReference;
33
import org.gvsig.fmap.dal.feature.FeatureSet;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.primitive.Point;
37
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.task.SimpleTaskStatus;
39
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
40
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
41
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
42
import org.gvsig.topology.lib.api.TopologyDataSet;
43
import org.gvsig.topology.lib.api.TopologyPlan;
44
import org.gvsig.topology.lib.api.TopologyReport;
45
import org.gvsig.topology.lib.api.TopologyReportLine;
46
import org.gvsig.topology.lib.api.TopologyRule;
47
import org.gvsig.topology.lib.api.TopologyRuleFactory;
48

  
49
/**
50
 *
51
 * @author jjdelcerro
52
 */
53
@SuppressWarnings("UseSpecificCatch")
54
public class PolygonContainsPointRule extends AbstractTopologyRule {
55

  
56
    private class CreateFetureAction extends AbstractTopologyRuleAction {
57

  
58
        public CreateFetureAction() {
59
            super(
60
                    PolygonContainsPointRuleFactory.NAME,
61
                    "CreateFeature",
62
                    "Create Feature",
63
                    "The Create Feature fix creates a new point feature at the centroid of the polygon feature that is causing the error. The point feature that is created is guaranteed to be within the polygon feature."
64
            );
65
        }
66

  
67
        @Override
68
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
69
            try {
70
                Geometry polygon = line.getGeometry();
71
                Point point = polygon.centroid();
72
                if( !polygon.contains(point) ) {
73
                    point = polygon.getInteriorPoint();
74
                }
75
                TopologyDataSet dataSet = rule.getDataSet2();
76

  
77
                EditableFeature feature = dataSet.createNewFeature();
78
                feature.setDefaultGeometry(point);
79
                dataSet.insert(feature);
80

  
81
            } catch (Exception ex) {
82
                throw new ExecuteTopologyRuleActionException(ex);
83
            }
84
        }
85

  
86
    }
87

  
88
    private String geomName;
89
    private Expression expression = null;
90
    private GeometryExpressionBuilder expressionBuilder = null;
91

  
92
    public PolygonContainsPointRule(
93
            TopologyPlan plan,
94
            TopologyRuleFactory factory,
95
            double tolerance,
96
            String dataSet1,
97
            String dataSet2
98
    ) {
99
        super(plan, factory, tolerance, dataSet1, dataSet2);
100

  
101
        this.addAction(new CreateFetureAction());
102
    }
103

  
104
    @Override
105
    protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception {
106
        FeatureSet set = null;
107
        try {
108
            FeatureStore store2 = this.getDataSet2().getFeatureStore();
109
            if (this.expression == null) {
110
                this.expression = ExpressionUtils.createExpression();
111
                this.expressionBuilder = GeometryExpressionUtils.createExpressionBuilder();
112
                this.geomName = store2.getDefaultFeatureType().getDefaultGeometryAttributeName();
113
            }
114
            Geometry polygon = feature1.getDefaultGeometry();
115
            TopologyDataSet theDataSet = this.getDataSet2();
116
            if (theDataSet.getSpatialIndex() != null) {
117
                boolean contains = false;
118
                for (FeatureReference featureReference : theDataSet.query(polygon)) {
119
                    Feature feature2 = featureReference.getFeature();
120
                    Geometry otherPoint = feature2.getDefaultGeometry();
121
                    if( otherPoint!=null && polygon.contains(otherPoint) ) {
122
                        contains = true;
123
                        break;
124
                    }
125
                }
126
                if( !contains ) {
127
                    report.addLine(this,
128
                            this.getDataSet1(),
129
                            this.getDataSet2(),
130
                            polygon,
131
                            polygon,
132
                            feature1.getReference(),
133
                            null,
134
                            false,
135
                            "The polygon is an error because it does not contain a point."
136
                    );
137
                }
138
            } else {
139
                this.expression.setPhrase(
140
                        this.expressionBuilder.ifnull(
141
                                this.expressionBuilder.column(this.geomName),
142
                                this.expressionBuilder.constant(false),
143
                                this.expressionBuilder.ST_Contains(
144
                                        this.expressionBuilder.geometry(polygon),
145
                                        this.expressionBuilder.column(this.geomName)
146
                                )
147
                        ).toString()
148
                );
149
                if (theDataSet.findFirst(this.expression) == null) {
150
                    report.addLine(this,
151
                            this.getDataSet1(),
152
                            this.getDataSet2(),
153
                            polygon,
154
                            polygon,
155
                            feature1.getReference(),
156
                            null,
157
                            false,
158
                            "The polygon is an error because it does not contain a point."
159
                    );
160
                }
161
            }
162
        } catch (Exception ex) {
163
            LOGGER.warn("Can't check feature.", ex);
164
        } finally {
165
            if (set != null) {
166
                set.dispose();
167
            }
168
        }
169
    }
170

  
171
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/PolygonMustBeCoveredByPolygonRule.java
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.topology.rule;
25

  
26
import org.gvsig.expressionevaluator.Expression;
27
import org.gvsig.expressionevaluator.ExpressionUtils;
28
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
29
import org.gvsig.expressionevaluator.GeometryExpressionUtils;
30
import org.gvsig.fmap.dal.feature.EditableFeature;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureReference;
33
import org.gvsig.fmap.dal.feature.FeatureSet;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.primitive.Point;
37
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.task.SimpleTaskStatus;
39
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
40
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
41
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
42
import org.gvsig.topology.lib.api.TopologyDataSet;
43
import org.gvsig.topology.lib.api.TopologyPlan;
44
import org.gvsig.topology.lib.api.TopologyReport;
45
import org.gvsig.topology.lib.api.TopologyReportLine;
46
import org.gvsig.topology.lib.api.TopologyRule;
47
import org.gvsig.topology.lib.api.TopologyRuleFactory;
48

  
49
/**
50
 *
51
 * @author jjdelcerro
52
 */
53
@SuppressWarnings("UseSpecificCatch")
54
public class PolygonMustBeCoveredByPolygonRule extends AbstractTopologyRule {
55

  
56
    private class CreateFetureAction extends AbstractTopologyRuleAction {
57

  
58
        public CreateFetureAction() {
59
            super(
60
                    PolygonContainsPointRuleFactory.NAME,
61
                    "CreateFeature",
62
                    "Create Feature (EN CONSTRUCCION)",
63
                    "The Create Feature fix creates a new polygon feature out of the portion of overlap from the existing polygon so the boundary of each feature from both feature classes is the same. This fix can be applied to one or more selected Must Be Covered By errors."
64
            );
65
        }
66

  
67
        @Override
68
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
69
            try {
70
//                Geometry polygon = line.getGeometry();
71
//                Point point = polygon.centroid();
72
//                if( !polygon.contains(point) ) {
73
//                    point = polygon.getInteriorPoint();
74
//                }
75
//                TopologyDataSet dataSet = rule.getDataSet2();
76
//
77
//                EditableFeature feature = dataSet.createNewFeature();
78
//                feature.setDefaultGeometry(point);
79
//                dataSet.insert(feature);
80

  
81
            } catch (Exception ex) {
82
                throw new ExecuteTopologyRuleActionException(ex);
83
            }
84
        }
85

  
86
    }
87
    
88
    private String geomName;
89
    private Expression expression = null;
90
    private GeometryExpressionBuilder expressionBuilder = null;
91

  
92
    public PolygonMustBeCoveredByPolygonRule(
93
            TopologyPlan plan,
94
            TopologyRuleFactory factory,
95
            double tolerance,
96
            String dataSet1,
97
            String dataSet2
98
    ) {
99
        super(plan, factory, tolerance, dataSet1, dataSet2);
100
        
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff