Statistics
| Revision:

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 @ 712

History | View | Annotate | Download (3.46 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.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.tools.dynobject.DynObject;
29
import org.gvsig.topology.lib.spi.AbstractTopologyRule;
30
import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction;
31
import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException;
32
import org.gvsig.topology.lib.api.TopologyDataSet;
33
import org.gvsig.topology.lib.api.TopologyPlan;
34
import org.gvsig.topology.lib.api.TopologyReport;
35
import org.gvsig.topology.lib.api.TopologyReportLine;
36
import org.gvsig.topology.lib.api.TopologyRule;
37
import org.gvsig.topology.lib.api.TopologyRuleFactory;
38

    
39
/**
40
 *
41
 * @author jjdelcerro
42
 */
43
@SuppressWarnings("UseSpecificCatch")
44
public class MustBeLargerThanToleranceLineRule extends AbstractTopologyRule {
45

    
46
    private class DeleteAction extends AbstractTopologyRuleAction {
47

    
48
        public DeleteAction() {
49
            super(
50
                MustBeLargerThanToleranceLineRuleFactory.NAME, 
51
                "delete", 
52
                "Delete", 
53
                "Removes line features that would collapse during the validate process based on the topology's tolerance."
54
            );
55
        }
56
        
57
        @Override
58
        public void execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) {
59
            try {
60
                TopologyDataSet dataset = line.getDataSet1();
61
                dataset.delete(line.getFeature1());
62
            } catch (Exception ex) {
63
                throw new ExecuteTopologyRuleActionException(ex);
64
            }
65
        }
66
        
67
    } 
68
    
69
    public MustBeLargerThanToleranceLineRule( 
70
            TopologyPlan plan,
71
            TopologyRuleFactory factory
72
    ) {
73
        super(plan, factory);
74
        this.actions.add(new DeleteAction());
75
    }
76
    
77
    public MustBeLargerThanToleranceLineRule( 
78
            TopologyPlan plan,
79
            TopologyRuleFactory factory,
80
            double tolerance,
81
            String dataSet1,
82
            String dataSet2
83

    
84
    ) {
85
        super(plan, factory, tolerance, dataSet1, dataSet2);
86
        this.actions.add(new DeleteAction());
87
    }
88
    
89
    @Override
90
    public void check(TopologyReport report, Feature feature) throws Exception {
91
        Geometry geom = feature.getDefaultGeometry();
92
        if( geom.perimeter()<this.getTolerance() ) {
93
            report.addLine(this, this.getDataSet1(), null, 
94
                    geom, feature.getReference(), null, false, 
95
                    "The length of the line is less than the specified tolerance"
96
            );
97
        }
98
    }
99

    
100

    
101
}