Statistics
| Revision:

root / trunk / libraries / libTopology / src / org / gvsig / topology / errorfixes / SubstractOverlapPolygonFix.java @ 23039

History | View | Annotate | Download (3.81 KB)

1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package org.gvsig.topology.errorfixes;
50

    
51
import java.util.ArrayList;
52
import java.util.List;
53

    
54
import org.gvsig.exceptions.BaseException;
55
import org.gvsig.fmap.core.FeatureUtil;
56
import org.gvsig.fmap.core.NewFConverter;
57
import org.gvsig.jts.JtsUtil;
58
import org.gvsig.topology.Messages;
59
import org.gvsig.topology.TopologyError;
60

    
61
import com.iver.cit.gvsig.fmap.core.IFeature;
62
import com.vividsolutions.jts.geom.Geometry;
63
import com.vividsolutions.jts.geom.GeometryCollection;
64

    
65
/**
66
 * Automatic fix to 'Polygon must not overlaps' topology error.
67
 * 
68
 * It removes from the two overlappings polygons their common area, leaving
69
 * a gap or void.
70
 * 
71
 * @author Alvaro Zabala
72
 *
73
 */
74
public class SubstractOverlapPolygonFix extends AbstractTopologyErrorFix {
75

    
76
        
77
        public List<IFeature>[] fixAlgorithm(TopologyError error) throws BaseException {
78
                Geometry errorJts = NewFConverter.toJtsGeometry(error.getGeometry());
79
                
80
                IFeature firstFeature = error.getFeature1();
81
                Geometry firstJts = NewFConverter.toJtsGeometry(firstFeature.getGeometry());
82
                
83
                IFeature secondFeature = error.getFeature2();
84
                Geometry secondJts = NewFConverter.toJtsGeometry(secondFeature.getGeometry());
85
        
86
                
87
                List<IFeature> editedFeatures = new ArrayList<IFeature>();
88
                
89
                //we could find three cases:
90
                //a) first covers second, we compute first difference second
91
                //b) they dont cover or are covered. we compute first difference second
92
                //c) second covers a, we compute second difference first, and modifies second
93
                if(secondJts.covers(firstJts)){
94
                        
95
                        //we remove the overlapped area from the container geometry
96
                        
97
                        secondFeature = FeatureUtil.removeOverlappingArea(secondFeature, 
98
                                                                                                                        secondJts, 
99
                                                                                                                        errorJts );
100
                        editedFeatures.add(secondFeature);
101
                        
102
                }else if(secondJts.coveredBy(firstJts))
103
                {
104
                        //we remove secondJts from firstJts
105
                        firstFeature = FeatureUtil.removeOverlappingArea(firstFeature, 
106
                                        firstJts, 
107
                                        errorJts );
108
                        editedFeatures.add(firstFeature);
109
                }else{
110
                        //we remove overlapping area from both features
111
                        firstFeature = FeatureUtil.removeOverlappingArea(firstFeature, 
112
                                        firstJts, 
113
                                        errorJts );
114
                        secondFeature = FeatureUtil.removeOverlappingArea(secondFeature, 
115
                                        secondJts, 
116
                                        errorJts );
117
                        editedFeatures.add(secondFeature);
118
                        editedFeatures.add(firstFeature);
119
                }
120
                return (List<IFeature>[]) new List[]{editedFeatures};
121
        }
122
        
123

    
124
        public String getEditionDescription() {
125
                return Messages.getText("SUBSTRACT_OVERLAP_AREA_FIX");
126
        }
127

    
128
}