root / trunk / libraries / libTopology / src / org / gvsig / jts / SnapCoordinateList.java @ 23048
History | View | Annotate | Download (3.51 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: SnapCoordinateList.java 23048 2008-09-01 15:06:47Z azabala $
|
47 |
* $Log: SnapCoordinateList.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 com.vividsolutions.jts.algorithms.SnapCGAlgorithms; |
56 |
import com.vividsolutions.jts.geom.Coordinate; |
57 |
import com.vividsolutions.jts.geom.CoordinateList; |
58 |
|
59 |
/**
|
60 |
* JTS coordinate list that uses snap to avoid consecutives coordinates at a
|
61 |
* distance lower than the cluster tolerance.
|
62 |
*
|
63 |
*
|
64 |
* FIXME There could be coordinates non consecutives at a distance slower than
|
65 |
* snap tolerance.
|
66 |
*
|
67 |
* @author azabala
|
68 |
*
|
69 |
*/
|
70 |
public class SnapCoordinateList extends CoordinateList { |
71 |
|
72 |
private static final long serialVersionUID = 8784078431309170433L; |
73 |
|
74 |
private double snapTolerance; |
75 |
|
76 |
|
77 |
public SnapCoordinateList(double snapTolerance) { |
78 |
super();
|
79 |
this.snapTolerance = snapTolerance;
|
80 |
} |
81 |
|
82 |
public SnapCoordinateList(Coordinate[] coord, double snapTolerance) { |
83 |
super();
|
84 |
this.snapTolerance = snapTolerance;
|
85 |
add(coord, false);//by default doesnt allow repeated coords |
86 |
} |
87 |
|
88 |
|
89 |
public SnapCoordinateList(Coordinate[] coord, |
90 |
double snapTolerance,
|
91 |
boolean allowRepeated) {
|
92 |
super();
|
93 |
this.snapTolerance = snapTolerance;
|
94 |
add(coord, allowRepeated); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* Add a coordinate
|
99 |
*
|
100 |
* @param coord
|
101 |
* The coordinates
|
102 |
* @param allowRepeated
|
103 |
* if set to false, repeated coordinates are collapsed
|
104 |
*/
|
105 |
public void add(Coordinate coord, boolean allowRepeated) { |
106 |
// don't add duplicate coordinates
|
107 |
if (!allowRepeated) {
|
108 |
// with this code we only filter consecutive snapped points
|
109 |
// if (size() >= 1) {
|
110 |
// Coordinate last = (Coordinate) get(size() - 1);
|
111 |
// if(SnapCGAlgorithms.snapEquals2D(last, coord, snapTolerance))
|
112 |
// return;
|
113 |
// }//if
|
114 |
int size = size();
|
115 |
/*
|
116 |
If size == 1, we check the existing point,
|
117 |
if size > 1, we dont check the first point (because closed geometries
|
118 |
musnt snap the first and last point
|
119 |
* */
|
120 |
if(size > 1){ |
121 |
for(int i = 1; i < size; i++){ |
122 |
Coordinate coordinate = (Coordinate) get(i); |
123 |
if(SnapCGAlgorithms.snapEquals2D(coordinate, coord, snapTolerance))
|
124 |
return;
|
125 |
} |
126 |
}else if(size == 1){ |
127 |
Coordinate last = (Coordinate) get(0);
|
128 |
if(SnapCGAlgorithms.snapEquals2D(last, coord, snapTolerance))
|
129 |
return;
|
130 |
} |
131 |
}//if
|
132 |
super.add(coord);
|
133 |
} |
134 |
} |