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 @ 725
History | View | Annotate | Download (8.33 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.FeatureReference; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.tools.dynobject.DynObject; |
34 |
import org.gvsig.tools.task.SimpleTaskStatus; |
35 |
import org.gvsig.topology.lib.spi.AbstractTopologyRule; |
36 |
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction; |
37 |
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException; |
38 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
39 |
import org.gvsig.topology.lib.api.TopologyPlan; |
40 |
import org.gvsig.topology.lib.api.TopologyReport; |
41 |
import org.gvsig.topology.lib.api.TopologyReportLine; |
42 |
import org.gvsig.topology.lib.api.TopologyRule; |
43 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
44 |
|
45 |
/**
|
46 |
*
|
47 |
* @author jjdelcerro
|
48 |
*/
|
49 |
@SuppressWarnings("UseSpecificCatch") |
50 |
public class MustNotOverlapPolygonRule extends AbstractTopologyRule { |
51 |
|
52 |
private class CreateFetureAction extends AbstractTopologyRuleAction { |
53 |
|
54 |
public CreateFetureAction() {
|
55 |
super(
|
56 |
MustNotOverlapPolygonRuleFactory.NAME, |
57 |
"CreateFeature",
|
58 |
"Create Feature",
|
59 |
"The Create Feature fix creates a new polygon feature out "
|
60 |
+ "of the error shape and removes the portion of "
|
61 |
+ "overlap from each of the features, causing the "
|
62 |
+ "error to create a planar representation of the "
|
63 |
+ "feature geometry. This fix can be applied to "
|
64 |
+ "one or more selected Must Not Overlap errors."
|
65 |
); |
66 |
} |
67 |
|
68 |
@Override
|
69 |
public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) { |
70 |
try {
|
71 |
// TODO
|
72 |
} catch (Exception ex) { |
73 |
throw new ExecuteTopologyRuleActionException(ex); |
74 |
} |
75 |
} |
76 |
|
77 |
} |
78 |
|
79 |
private class SubtractAction extends AbstractTopologyRuleAction { |
80 |
|
81 |
public SubtractAction() {
|
82 |
super(
|
83 |
MustNotOverlapPolygonRuleFactory.NAME, |
84 |
"Subtract",
|
85 |
"Subtract",
|
86 |
"The Subtract fix removes the overlapping portion of "
|
87 |
+ "geometry from each feature that is causing the "
|
88 |
+ "error and leaves a gap or void in its place. "
|
89 |
+ "This fix can be applied to one or more selected "
|
90 |
+ "Must Not Overlap errors."
|
91 |
); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) { |
96 |
try {
|
97 |
// TODO
|
98 |
} catch (Exception ex) { |
99 |
throw new ExecuteTopologyRuleActionException(ex); |
100 |
} |
101 |
} |
102 |
|
103 |
} |
104 |
|
105 |
private class MergeAction extends AbstractTopologyRuleAction { |
106 |
|
107 |
public MergeAction() {
|
108 |
super(
|
109 |
MustNotOverlapPolygonRuleFactory.NAME, |
110 |
"Merge",
|
111 |
"Merge",
|
112 |
"The Merge fix adds the portion of overlap from one feature "
|
113 |
+ "and subtracts it from the others that are "
|
114 |
+ "violating the rule. You need to pick the feature "
|
115 |
+ "that receives the portion of overlap using the "
|
116 |
+ "Merge dialog box. This fix can be applied to one "
|
117 |
+ "Must Not Overlap error only."
|
118 |
); |
119 |
} |
120 |
|
121 |
@Override
|
122 |
public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) { |
123 |
try {
|
124 |
// TODO
|
125 |
} catch (Exception ex) { |
126 |
throw new ExecuteTopologyRuleActionException(ex); |
127 |
} |
128 |
} |
129 |
} |
130 |
|
131 |
private String geomName; |
132 |
private Expression expression = null; |
133 |
private ExpressionBuilder expressionBuilder = null; |
134 |
|
135 |
public MustNotOverlapPolygonRule(
|
136 |
TopologyPlan plan, |
137 |
TopologyRuleFactory factory |
138 |
) { |
139 |
super(plan, factory);
|
140 |
this.addAction(new CreateFetureAction()); |
141 |
this.addAction(new MergeAction()); |
142 |
this.addAction(new SubtractAction()); |
143 |
} |
144 |
|
145 |
public MustNotOverlapPolygonRule(
|
146 |
TopologyPlan plan, |
147 |
TopologyRuleFactory factory, |
148 |
double tolerance,
|
149 |
String dataSet1
|
150 |
) { |
151 |
super(plan, factory, tolerance, dataSet1);
|
152 |
this.addAction(new CreateFetureAction()); |
153 |
this.addAction(new MergeAction()); |
154 |
this.addAction(new SubtractAction()); |
155 |
} |
156 |
|
157 |
@Override
|
158 |
protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception { |
159 |
try {
|
160 |
if (this.expression == null) { |
161 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
162 |
this.expression = manager.createExpression();
|
163 |
this.expressionBuilder = manager.createExpressionBuilder();
|
164 |
this.geomName = feature1.getType().getDefaultGeometryAttributeName();
|
165 |
} |
166 |
Geometry polygon = feature1.getDefaultGeometry(); |
167 |
if( polygon==null ) { |
168 |
return;
|
169 |
} |
170 |
TopologyDataSet theDataSet = this.getDataSet1();
|
171 |
if (theDataSet.getSpatialIndex() != null) { |
172 |
for (FeatureReference reference : theDataSet.query(polygon)) {
|
173 |
if (reference.equals(feature1.getReference())) {
|
174 |
continue;
|
175 |
} |
176 |
Feature feature = reference.getFeature(); |
177 |
if (polygon.overlaps(feature.getDefaultGeometry())) {
|
178 |
report.addLine(this,
|
179 |
theDataSet, |
180 |
null,
|
181 |
polygon, |
182 |
feature1.getReference(), |
183 |
null,
|
184 |
false,
|
185 |
"The polygon overlay with others."
|
186 |
); |
187 |
break;
|
188 |
} |
189 |
} |
190 |
} else {
|
191 |
this.expression.setPhrase(
|
192 |
this.expressionBuilder.ifnull(
|
193 |
this.expressionBuilder.column(this.geomName), |
194 |
this.expressionBuilder.constant(false), |
195 |
this.expressionBuilder.ST_Overlaps(
|
196 |
this.expressionBuilder.column(this.geomName), |
197 |
this.expressionBuilder.geometry(polygon)
|
198 |
) |
199 |
).toString() |
200 |
); |
201 |
if (theDataSet.findFirst(this.expression) != null) { |
202 |
report.addLine(this,
|
203 |
theDataSet, |
204 |
null,
|
205 |
polygon, |
206 |
feature1.getReference(), |
207 |
null,
|
208 |
false,
|
209 |
"The polygon overlay with others."
|
210 |
); |
211 |
} |
212 |
} |
213 |
} catch (Exception ex) { |
214 |
LOGGER.warn("Can't check feature.", ex);
|
215 |
} finally {
|
216 |
} |
217 |
} |
218 |
|
219 |
} |