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 / MustBeLargerThanToleranceLineRule.java @ 727
History | View | Annotate | Download (3.33 KB)
1 | 688 | jjdelcerro | /**
|
---|---|---|---|
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 | 721 | jjdelcerro | import org.gvsig.tools.task.SimpleTaskStatus; |
30 | 688 | jjdelcerro | 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 | 712 | jjdelcerro | MustBeLargerThanToleranceLineRuleFactory.NAME, |
52 | 688 | jjdelcerro | "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 | 722 | jjdelcerro | this.addAction(new DeleteAction()); |
80 | 688 | jjdelcerro | } |
81 | |||
82 | @Override
|
||
83 | 721 | jjdelcerro | public void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature) throws Exception { |
84 | 688 | jjdelcerro | Geometry geom = feature.getDefaultGeometry(); |
85 | if( geom.perimeter()<this.getTolerance() ) { |
||
86 | 727 | jjdelcerro | report.addLine(this, this.getDataSet1(), null, |
87 | geom, null, feature.getReference(), null, false, |
||
88 | 688 | jjdelcerro | "The length of the line is less than the specified tolerance"
|
89 | ); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | |||
94 | } |