Revision 712

View differences:

org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/AbstractTopologyRuleFactory.java
47 47
            String id,
48 48
            String name,
49 49
            String description,
50
            int geometryTypeDataSet1,
51
            int geometryTypeDataSet2
52
        ) {
53
        this(
54
                id, 
55
                name, 
56
                description, 
57
                ListBuilder.create(geometryTypeDataSet1), 
58
                ListBuilder.create(geometryTypeDataSet2)
59
        );
60
    }
61

  
62
    protected AbstractTopologyRuleFactory(
63
            String id,
64
            String name,
65
            String description,
66 50
            List<Integer> geometryTypeDataSet1,
67
            int geometryTypeDataSet2
68
        ) {
69
        this(
70
                id, 
71
                name, 
72
                description, 
73
                geometryTypeDataSet1, 
74
                ListBuilder.create(geometryTypeDataSet2)
75
        );
76
    }
77

  
78
    protected AbstractTopologyRuleFactory(
79
            String id,
80
            String name,
81
            String description,
82
            int geometryTypeDataSet1,
83 51
            List<Integer> geometryTypeDataSet2
84 52
        ) {
85
        this(
86
                id, 
87
                name, 
88
                description, 
89
                ListBuilder.create(geometryTypeDataSet1), 
90
                geometryTypeDataSet2
91
        );
92
    }
93

  
94
    protected AbstractTopologyRuleFactory(
95
            String id,
96
            String name,
97
            String description,
98
            List<Integer> geometryTypeDataSet1,
99
            List<Integer> geometryTypeDataSet2
100
        ) {
101 53
        this.id = id;
102 54
        this.name = name;
103 55
        this.description = description;
......
110 62
            String id,
111 63
            String name,
112 64
            String description,
113
            int geometryTypeDataSet1
65
            List<Integer> geometryTypeDataSet1
114 66
        ) {
115
        this(id, name, description, geometryTypeDataSet1, Geometry.TYPES.NULL);
67
        this(id, name, description, geometryTypeDataSet1, null);
116 68
    }
117
    
69

  
118 70
    @Override
119 71
    public String toString() {
120 72
        return this.name;
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/RuleResourceLoaderUtils.java
5 5
 */
6 6
package org.gvsig.topology.lib.spi;
7 7

  
8
import java.io.File;
8 9
import java.io.InputStream;
10
import java.net.MalformedURLException;
9 11
import java.net.URL;
10 12
import java.util.List;
11 13
import java.util.Locale;
14
import java.util.logging.Level;
12 15
import org.apache.commons.io.IOUtils;
13 16
import org.apache.commons.lang3.StringUtils;
14 17
import org.json.JSONArray;
......
37 40
        return url;
38 41
    }
39 42
    
40
    public static JSONObject getRule(String idRule) {
41
        URL url = getRuleURL(idRule);
43
    public static JSONObject getRule(URL url) {
42 44
        if( url == null ) {
43 45
            return null;
44 46
        }
......
57 59
        return json;
58 60
    }
59 61

  
62
    public static JSONObject getRule(String idRuleOrPathname) {
63
        if( idRuleOrPathname==null ) {
64
            return null;
65
        }
66
        if( idRuleOrPathname.endsWith(".json") ) {
67
            // Asumimos que es una ruta al fichero json.
68
            return getRule(new File(idRuleOrPathname));
69
        }
70
        // Asumimos que es un ID de regla
71
        URL url = getRuleURL(idRuleOrPathname);
72
        if( url == null ) {
73
            return null;
74
        }
75
        return getRule(url);
76
    }
77
    
78
    public static JSONObject getRule(File jsonfile) {
79
        if( jsonfile == null || !jsonfile.exists() ) {
80
            return null;
81
        }
82
        try {
83
            return getRule(jsonfile.toURI().toURL());
84
        } catch (MalformedURLException ex) {
85
            LOGGER.warn("Can't load resource from json file '"+jsonfile.toString()+"'.", ex);
86
            return null;
87
        }
88
    }
89

  
60 90
    public static String getDescription(String idRule, JSONObject json) {
61 91
        String description = null;
62 92
        
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/AbstractTopologyRule.java
86 86
        this.dataSet2 = dataSet2;
87 87
    }
88 88

  
89
    protected AbstractTopologyRule(
90
            TopologyPlan plan,
91
            TopologyRuleFactory factory,
92
            double tolerance,
93
            String dataSet1
94
    ) {
95
        this(plan, factory, tolerance, dataSet1, null);
96
    }
97

  
89 98
    protected TopologyPlan getPlan() {
90 99
        return this.plan;
91 100
    }
92 101

  
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
33 33
import org.gvsig.topology.lib.api.TopologyManager;
34 34
import org.gvsig.topology.rule.ContainsPointRuleFactory;
35 35
import org.gvsig.topology.rule.MustBeLargerThanToleranceLineRuleFactory;
36
import org.gvsig.topology.rule.MustNotOverlapPolygonRuleFactory;
36 37

  
37 38
/**
38 39
 *
......
59 60
        TopologyManager manager = TopologyLocator.getTopologyManager();
60 61
        manager.addRuleFactories(new ContainsPointRuleFactory());
61 62
        manager.addRuleFactories(new MustBeLargerThanToleranceLineRuleFactory());
63
        manager.addRuleFactories(new MustNotOverlapPolygonRuleFactory());
62 64
    }
63 65

  
64 66
}
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
24 24
package org.gvsig.topology.rule;
25 25

  
26 26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.tools.util.ListBuilder;
27 28
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory;
28 29
import org.gvsig.topology.lib.api.TopologyPlan;
29 30
import org.gvsig.topology.lib.api.TopologyRule;
......
34 35
 */
35 36
public class MustBeLargerThanToleranceLineRuleFactory extends AbstractTopologyRuleFactory {
36 37

  
38
    public static final String NAME = "MustBeLargerThanToleranceLine";
39
    
37 40
    public MustBeLargerThanToleranceLineRuleFactory() {
38 41
        super(
39
                "MustBeLargerThanToleranceLine", 
42
                NAME, 
40 43
                "Must Be Larger Than Tolerance", 
41 44
                "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", 
42
                Geometry.TYPES.CURVE, 
43
                Geometry.TYPES.NULL
45
                new ListBuilder<Integer>()
46
                        .add(Geometry.TYPES.CURVE)
47
                        .asList()
44 48
        );
45 49
    }
46 50
    
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
55 55

  
56 56
        public CreateFetureAction() {
57 57
            super(
58
                    "ContainsPoint",
58
                    ContainsPointRuleFactory.NAME,
59 59
                    "CreateFeature",
60 60
                    "Create Feature",
61 61
                    "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."
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.ExpressionBuilder;
28
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
29
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.tools.dynobject.DynObject;
34
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
35
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
36
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
37
import org.gvsig.topology.lib.api.TopologyDataSet;
38
import org.gvsig.topology.lib.api.TopologyPlan;
39
import org.gvsig.topology.lib.api.TopologyReport;
40
import org.gvsig.topology.lib.api.TopologyReportLine;
41
import org.gvsig.topology.lib.api.TopologyRule;
42
import org.gvsig.topology.lib.api.TopologyRuleFactory;
43

  
44
/**
45
 *
46
 * @author jjdelcerro
47
 */
48
@SuppressWarnings("UseSpecificCatch")
49
public class MustNotOverlapPolygonRule extends AbstractTopologyRule {
50

  
51
    private class CreateFetureAction extends AbstractTopologyRuleAction {
52

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

  
67
        @Override
68
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters)  {
69
            try {
70
                // TODO
71
            } catch (Exception ex) {
72
                throw new ExecuteTopologyRuleActionException(ex);
73
            }
74
        }
75

  
76
    }
77

  
78
    private class SubtractAction extends AbstractTopologyRuleAction {
79

  
80
        public SubtractAction() {
81
            super(
82
                    MustNotOverlapPolygonRuleFactory.NAME,
83
                    "Subtract",
84
                    "Subtract",
85
                    "The Subtract fix removes the overlapping portion of "
86
                            + "geometry from each feature that is causing the "
87
                            + "error and leaves a gap or void in its place. "
88
                            + "This fix can be applied to one or more selected "
89
                            + "Must Not Overlap errors."
90
            );
91
        }
92

  
93
        @Override
94
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters)  {
95
            try {
96
                // TODO
97
            } catch (Exception ex) {
98
                throw new ExecuteTopologyRuleActionException(ex);
99
            }
100
        }
101

  
102
    }
103

  
104
    private class MergeAction extends AbstractTopologyRuleAction {
105

  
106
        public MergeAction() {
107
            super(
108
                    MustNotOverlapPolygonRuleFactory.NAME,
109
                    "Merge",
110
                    "Merge",
111
                    "The Merge fix adds the portion of overlap from one feature "
112
                            + "and subtracts it from the others that are "
113
                            + "violating the rule. You need to pick the feature "
114
                            + "that receives the portion of overlap using the "
115
                            + "Merge dialog box. This fix can be applied to one "
116
                            + "Must Not Overlap error only."
117
            );
118
        }
119

  
120
        @Override
121
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters)  {
122
            try {
123
                // TODO
124
            } catch (Exception ex) {
125
                throw new ExecuteTopologyRuleActionException(ex);
126
            }
127
        }
128
    }
129
    
130
    private String geomName;
131
    private Expression expression = null;
132
    private ExpressionBuilder expressionBuilder = null;
133
    
134
    public MustNotOverlapPolygonRule(
135
            TopologyPlan plan,
136
            TopologyRuleFactory factory
137
    ) {
138
        super(plan, factory);
139
        this.actions.add(new CreateFetureAction());
140
        this.actions.add(new MergeAction());
141
        this.actions.add(new SubtractAction());
142
    }
143
    
144
    public MustNotOverlapPolygonRule(
145
            TopologyPlan plan,
146
            TopologyRuleFactory factory,
147
            double tolerance,
148
            String dataSet1
149
    ) {
150
        super(plan, factory, tolerance, dataSet1);
151
        this.actions.add(new CreateFetureAction());
152
    }
153

  
154
    @Override
155
    protected void check(TopologyReport report, Feature feature1, TopologyDataSet dataSet2) throws Exception {
156
        try {
157
            if( this.expression == null ) {
158
                ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
159
                this.expression = manager.createExpression();
160
                this.expressionBuilder = manager.createExpressionBuilder();
161
                this.geomName = feature1.getType().getDefaultGeometryAttributeName();
162
             }
163
            Geometry polygon = feature1.getDefaultGeometry();
164
            this.expression.setPhrase(
165
                this.expressionBuilder.ST_Intersects(
166
                    this.expressionBuilder.column(this.geomName),
167
                    this.expressionBuilder.geometry(polygon)
168
                ).toString()
169
            );
170
            FeatureStore store = this.getDataSet1().getStore();
171
            Feature f = store.findFirst(this.expression);
172
            if ( f!=null ) {
173
                report.addLine(this,
174
                        this.getDataSet1(),
175
                        null,
176
                        polygon,
177
                        feature1.getReference(),
178
                        null,
179
                        false,
180
                        "The polygon overlay with others."
181
                );
182
            }
183
            
184
        } catch(Exception ex) {
185
            LOGGER.warn("Can't check feature.", ex);
186
        } finally {
187
        }
188
    }
189

  
190
}
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
47 47

  
48 48
        public DeleteAction() {
49 49
            super(
50
                "MustBeLargerThanToleranceLine", 
50
                MustBeLargerThanToleranceLineRuleFactory.NAME, 
51 51
                "delete", 
52 52
                "Delete", 
53 53
                "Removes line features that would collapse during the validate process based on the topology's tolerance."
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
35 35
 */
36 36
public class ContainsPointRuleFactory extends AbstractTopologyRuleFactory {
37 37
    
38
    public static final String NAME = "ContainsPoint";
39
    
38 40
    public ContainsPointRuleFactory() {
39 41
        super(
40
                "ContainsPoint", 
42
                NAME, 
41 43
                "Contains Point", 
42 44
                "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. ", 
43 45
                new ListBuilder<Integer>()
44 46
                        .add(Geometry.TYPES.SURFACE)
45 47
                        .add(Geometry.TYPES.MULTISURFACE)
46 48
                        .asList(),
47
                Geometry.TYPES.POINT
49
                new ListBuilder<Integer>()
50
                        .add(Geometry.TYPES.POINT)
51
                        .asList()
48 52
        );
49 53
    }
50 54
    
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.spi.AbstractTopologyRuleFactory;
29
import org.gvsig.topology.lib.api.TopologyPlan;
30
import org.gvsig.topology.lib.api.TopologyRule;
31

  
32
/**
33
 *
34
 * @author jjdelcerro
35
 */
36
public class MustNotOverlapPolygonRuleFactory extends AbstractTopologyRuleFactory {
37

  
38
    public static final String NAME = "MustNotOverlapPolygon";
39
    
40
    public MustNotOverlapPolygonRuleFactory() {
41
        super(
42
                NAME, 
43
                "Must Not Overlap", 
44
                "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.", 
45
                new ListBuilder<Integer>()
46
                        .add(Geometry.TYPES.SURFACE)
47
                        .add(Geometry.TYPES.MULTISURFACE)
48
                        .asList()
49
                
50
        );
51
    }
52
    
53
    @Override
54
    public TopologyRule createRule(TopologyPlan plan, String dataSet1, String dataSet2, double tolerance) {
55
        TopologyRule rule = new MustNotOverlapPolygonRule(plan, this, tolerance, dataSet1);
56
        return rule;
57
    }    
58

  
59
    @Override
60
    public TopologyRule createRule(TopologyPlan plan) {
61
        TopologyRule rule = new MustNotOverlapPolygonRule(plan, this);
62
        return rule;
63
    }
64
}
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/resources/org/gvsig/topology/rules/es/ContainsPoint.json
2 2
    "id": "ContainsPoint",
3 3
    "name": "Contiene un punto",
4 4
    "description": [ 
5
        "<img src=\"@@@.d/ContainsPoint.png\">\n",
5
        "<img src=\"@@@.d/contains_point2.png\">\n",
6
        "El poligono superior es un error porque no contiene ningun punto.\n\n",
6 7
        "Requiere que cada poligono del conjunto de datos contenga al menos un punto del otro conjunto de datos.\n",
7 8
        "Los puntos deben estar contenidos en el poligono, no en su perimetro,\n"
8 9
    ],
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/resources/org/gvsig/topology/rules/en/ContainsPoint.json
2 2
    "id": "ContainsPoint",
3 3
    "name": "Contains Point",
4 4
    "description": [ 
5
        "<img src=\"@@@.d/ContainsPoint.png\">\n",
6
        "Requires that a polygon in the primary dataset contain at least one point from the secondary dataset.\n",
7
        "Points must be within the polygon, not on the boundary.\n"
5
        "<img src=\"@@@.d/contains_point2.png\">\n",
6
        "The top polygon is an error because it does not contain a point.\n\n",
7
        "Requires that a polygon in the primary dataset contain at least one",
8
        "point from the secondary dataset.\n",
9
        "Points must be within the polygon, not on the boundary.\n",
10
        "This is useful when every polygon should have at least one associated",
11
        "point, such as when parcels must have an address point.
8 12
    ],
9 13
    "actions" : {
10 14
        "CreateFeature": {
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/resources/org/gvsig/topology/rules/en/MustNotOverlapPolygon.json
1
{
2
    "id": "MustNotOverlapPolygon",
3
    "name": "Must Not Overlap",
4
    "description": [ 
5
        "<img src=\"@@@.d/must_not_overlap.png\">\n",
6
        "Requires that the interior of polygons in the dataset not overlap.",
7
        "The polygons can share edges or vertices.",
8
        "This rule is used when an area cannot belong to two or more polygons.",
9
        "It is useful for modeling administrative boundaries, such as ZIP Codes",
10
        "or voting districts, and mutually exclusive area classifications,",
11
        "such as land cover or landform type."
12
    ],
13
    "actions" : {
14
        "CreateFeature": {
15
            "name" : "Create feature",
16
            "description": [ 
17
                "The Create Feature fix creates a new polygon feature out of",
18
                "the error shape and removes the portion of overlap from each",
19
                "of the features, causing the error to create a planar",
20
                "representation of the feature geometry.\n",
21
                "This fix can be applied to one or more selected Must Not Overlap errors."
22
            ]
23
        },
24
        "Subtract": {
25
            "name" : "Subtract",
26
            "description": [ 
27
                "The Subtract fix removes the overlapping portion of geometry",
28
                "from each feature that is causing the error and leaves a gap",
29
                "or void in its place. This fix can be applied to one or more",
30
                "selected Must Not Overlap errors."
31
            ]
32
        },
33
        "Merge": {
34
            "name" : "Merge",
35
            "description": [ 
36
                "The Merge fix adds the portion of overlap from one feature",
37
                "and subtracts it from the others that are violating the rule.",
38
                "You need to pick the feature that receives the portion of",
39
                "overlap using the Merge dialog box.",
40
                "This fix can be applied to one Must Not Overlap error only."
41
            ]
42
        }
43
    }
44
}
45

  
0 46

  
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.swing/org.gvsig.topology.swing.impl/src/main/java/org/gvsig/topology/swing/impl/CreateRuleDialog.java
198 198
        } catch (Exception ex) {
199 199

  
200 200
        }
201
        TopologyRule rule = ruleFactory.createRule(plan, dataSet1.getName(), dataSet2.getName(), tolerance);
201
        TopologyRule rule;
202
        if( dataSet2==null ) {
203
            rule = ruleFactory.createRule(plan, dataSet1.getName(), null, tolerance);
204
        } else {
205
            rule = ruleFactory.createRule(plan, dataSet1.getName(), dataSet2.getName(), tolerance);
206
        }
202 207
        return rule;
203 208
    }
204 209

  
205 210

  

Also available in: Unified diff