Revision 5286
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/GeometryIsValidFactory.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2021 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.json.Json; |
|
28 |
import org.gvsig.tools.util.ListBuilder; |
|
29 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
30 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
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 GeometryIsValidFactory extends AbstractTopologyRuleFactory { |
|
40 |
|
|
41 |
public static final String NAME = "GeometryIsValid"; |
|
42 |
|
|
43 |
public GeometryIsValidFactory() { |
|
44 |
super( |
|
45 |
NAME, |
|
46 |
"Geometry must be valid", |
|
47 |
"Requires that geometries are valid", |
|
48 |
new ListBuilder<Integer>() |
|
49 |
.add(Geometry.TYPES.GEOMETRY) |
|
50 |
.asList(), |
|
51 |
null |
|
52 |
); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public TopologyRule createRule(String dataSet1, String dataSet2, double tolerance) { |
|
57 |
TopologyRule rule = new GeometryIsValidRule(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 GeometryIsValidFactory()); |
|
66 |
Json.registerSerializer(GeometryIsValidRule.class); |
|
67 |
} catch(Exception ex) { |
|
68 |
LOGGER.warn("Can't register topology rule from GeometryIsValidRuleFactory.", ex); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/GeometryIsValidRule.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2021 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.fmap.geom.Geometry; |
|
29 |
import org.gvsig.tools.ToolsLocator; |
|
30 |
import org.gvsig.tools.i18n.I18nManager; |
|
31 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
32 |
import org.gvsig.topology.lib.api.TopologyReport; |
|
33 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
|
34 |
import org.gvsig.topology.lib.spi.AbstractTopologyRule; |
|
35 |
|
|
36 |
/** |
|
37 |
* |
|
38 |
* @author jjdelcerro |
|
39 |
*/ |
|
40 |
@SuppressWarnings("UseSpecificCatch") |
|
41 |
public class GeometryIsValidRule extends AbstractTopologyRule { |
|
42 |
|
|
43 |
public GeometryIsValidRule() { |
|
44 |
// for persistence only |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
public GeometryIsValidRule( |
|
49 |
TopologyRuleFactory factory, |
|
50 |
double tolerance, |
|
51 |
String dataSet1, |
|
52 |
String dataSet2 |
|
53 |
) { |
|
54 |
super(factory, tolerance, dataSet1, dataSet2); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception { |
|
59 |
FeatureSet set = null; |
|
60 |
try { |
|
61 |
Geometry geom = feature1.getDefaultGeometry(); |
|
62 |
Geometry.ValidationStatus status = geom.getValidationStatus(); |
|
63 |
if ( !status.isValid() ) { |
|
64 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
65 |
report.addLine(this, |
|
66 |
this.getDataSet1(), |
|
67 |
this.getDataSet2(), |
|
68 |
feature1.getDefaultGeometry(), |
|
69 |
status.getProblemLocation(), |
|
70 |
feature1.getReference(), |
|
71 |
null, |
|
72 |
false, |
|
73 |
i18n.getTranslation("_The_geometry_is_not_valid")+". "+status.getMessage() |
|
74 |
); |
|
75 |
} |
|
76 |
} catch(Exception ex) { |
|
77 |
LOGGER.warn("Can't check feature.", ex); |
|
78 |
addCodeException(report, feature1, ex); |
|
79 |
} finally { |
|
80 |
if( set!=null ) { |
|
81 |
set.dispose(); |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
} |
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.impl.customizablerule.CustomizableRule0ActionsFactory; |
34 |
import org.gvsig.topology.rule.GeometryIsValidFactory; |
|
34 | 35 |
import org.gvsig.topology.rule.GeometryMustNotBeNullRuleFactory; |
35 | 36 |
import org.gvsig.topology.rule.LineMustBeCoveredByBoundaryOfPolygonRuleFactory; |
36 | 37 |
import org.gvsig.topology.rule.PolygonContainsPointRuleFactory; |
... | ... | |
75 | 76 |
PolygonContainsPolygonRuleFactory.selfRegister(); |
76 | 77 |
PolygonContainsOnePointRuleFactory.selfRegister(); |
77 | 78 |
PolygonMustNotOverlapWithPolygonRuleFactory.selfRegister(); |
79 |
GeometryIsValidFactory.selfRegister(); |
|
78 | 80 |
} |
79 | 81 |
|
80 | 82 |
} |
Also available in: Unified diff