Statistics
| Revision:

root / trunk / libraries / libTopology / src / org / gvsig / jts / SnapRepeatedPointTester.java @ 23048

History | View | Annotate | Download (3.29 KB)

1
/*
2
 * Created on 19-sep-2007
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: SnapRepeatedPointTester.java 14147 2007-09-27 19:02:04Z azabala $
47
* $Log: SnapRepeatedPointTester.java,v $
48
* Revision 1.1  2007/09/19 16:37:49  azabala
49
* first version in cvs
50
*
51
*
52
*/
53
package org.gvsig.jts;
54

    
55
import java.util.Collection;
56

    
57
import com.iver.cit.gvsig.util.SnappingCoordinateMap;
58
import com.vividsolutions.jts.algorithms.SnapCGAlgorithms;
59
import com.vividsolutions.jts.geom.Coordinate;
60
import com.vividsolutions.jts.geom.Geometry;
61
import com.vividsolutions.jts.geom.GeometryCollection;
62
import com.vividsolutions.jts.geom.MultiPoint;
63

    
64
/**
65
 * RepeatedPointTester implementation that consideers a snap tolerance
66
 * (points that are at a distance lower than the snap tolerance are consideered
67
 * the same point)
68
 * 
69
 * @author azabala
70
 *
71
 */
72
public class SnapRepeatedPointTester extends RepeatedPointTester {
73
        
74
        private double snapTolerance;
75
        
76
        private SnappingCoordinateMap repeatedCoords;
77
        
78
        /**
79
         * Constructor 
80
         * @param snapTolerance
81
         */
82
        public SnapRepeatedPointTester(double snapTolerance) {
83
                repeatedCoords = new SnappingCoordinateMap(snapTolerance);
84
                this.snapTolerance = snapTolerance;
85
        }
86
        
87
        public Collection<Coordinate> getRepeatedCoordinates() {
88
                return repeatedCoords.values();
89
        }
90
        
91
        public void clear(){
92
                repeatedCoords.clear();
93
        }
94
        
95
        
96
        public boolean hasRepeatedPoint(Coordinate[] coords) {
97
                boolean solution = false;
98
                for (int i = 1; i < coords.length; i++) {
99
                        Coordinate previousCoord = coords[i - 1];
100
                        Coordinate coord = coords[i];
101
                        if(SnapCGAlgorithms.snapEquals2D(previousCoord, coord, snapTolerance)){
102
                                if(repeatedCoords.get(coords[i]) == null)
103
                                        repeatedCoords.put(coords[i], coords[i]);
104
                                solution = true;
105
                        }
106
                }// for
107
                return solution;
108
        }
109
        
110
        
111
        public Geometry removeRepeatedPoints(Geometry g){
112
                
113
                if(g instanceof GeometryCollection){
114
                        if(! (g instanceof MultiPoint))
115
                                return removeRepeatedPoints((GeometryCollection)g);
116
                }
117
                Coordinate[] coords = g.getCoordinates();
118
                SnapCoordinateList coordList = new SnapCoordinateList(coords, snapTolerance, false);
119
                Coordinate[] correctedCoords = coordList.toCoordinateArray();
120
                return JtsUtil.createGeometry(correctedCoords, g.getGeometryType());
121
        }
122
        
123
}
124