gvsig-projects-pool / 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 @ 712
History | View | Annotate | Download (7.08 KB)
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 |
} |