Revision 31124
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/plantilla.htm | ||
---|---|---|
1 |
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> |
|
2 |
<html> |
|
3 |
<head> |
|
4 |
<title>Documento sin título</title> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
|
6 |
<style type='text/css'> |
|
7 |
<!-- .normal { font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-style: normal; color: #333333;} h1 { |
|
8 |
font-family: Arial, Helvetica, sans-serif; |
|
9 |
font-size: 14px; |
|
10 |
} |
|
11 |
a { |
|
12 |
font-family: Arial, Helvetica, sans-serif; |
|
13 |
font-size: 10px; |
|
14 |
font-style: italic; |
|
15 |
font-weight: bold; |
|
16 |
} |
|
17 |
.distancia { |
|
18 |
font-family: Arial, Helvetica, sans-serif; |
|
19 |
font-size: 10px; |
|
20 |
color: #666666; |
|
21 |
} |
|
22 |
.resumen { |
|
23 |
font-family: Arial, Helvetica, sans-serif; |
|
24 |
font-size: 12px; |
|
25 |
color: #333333; |
|
26 |
} |
|
27 |
.left { |
|
28 |
color: #990000; |
|
29 |
font-weight: bold; |
|
30 |
} |
|
31 |
.right { |
|
32 |
color: #0033FF; |
|
33 |
font-weight: bold; |
|
34 |
} |
|
35 |
--> |
|
36 |
</style> |
|
37 |
</head> |
|
38 |
|
|
39 |
<body> |
|
40 |
<h1>Informe de Ruta:SOMONTES AL PALACIO DE LA REAL QUINTA-MONTE CARMELO</h1> |
|
41 |
<br> |
|
42 |
<span class="resumen"> Salida desde: <b>SOMONTES AL PALACIO DE LA REAL QUINTA</b><br> |
|
43 |
Llegada a:<b> MONTE CARMELO</b><br> |
|
44 |
Longitud total del trayecto: <b>9,020.31</b></span> |
|
45 |
<hr width ="70%"> |
|
46 |
<table> |
|
47 |
<tr> |
|
48 |
<td width="40"><img src="images/drapeau_depart.gif" width="18" height="26"></td> |
|
49 |
<td class='normal'>1. Salir de:<b> SOMONTES AL PALACIO DE LA REAL QUINTA</b></td></tr><tr> |
|
50 |
<td width="40" class='normal'> |
|
51 |
<td><a href="images/0">Ver sobre el mapa</a></tr></table><hr width ="70%"> |
|
52 |
<table> |
|
53 |
<tr> |
|
54 |
<td width="40"><img src="images/turn-left.png" width="32" height="32"></td> |
|
55 |
<td class='normal'>2 Contin?e por <b>SOMONTES AL PALACIO DE LA REAL QUINTA</b> |
|
56 |
durante 447.44 y gire a la <span class="left"><b>izquierda</b></span> por |
|
57 |
<b>M-30 (CTRA DEL PARDO)</b></td> |
|
58 |
</tr><tr> |
|
59 |
<td width="40"> </td> |
|
60 |
<td class="distancia">Distancia acumulada: 447.44 metros</td> |
|
61 |
</tr><tr> |
|
62 |
<td width="40"> |
|
63 |
<td><a href="images/0">Ver sobre el mapa</a></tr></table><hr width ="70%"> |
|
64 |
<table> |
|
65 |
<tr> |
|
66 |
<td width="40"><img src="images/turn-left.png" width="32" height="32"></td> |
|
67 |
<td class='normal'>3 Contin?e por <b>M-30 (CTRA DEL PARDO)</b> durante 2,320.58 y gire a la <b>izquierda</b> por <b>LA ALBERCA</b></td></tr><tr> |
|
68 |
<td width="40"> </td> |
|
69 |
<td class="distancia">Distancia acumulada: 2,768.02</td> |
|
70 |
</tr><tr> |
|
71 |
<td width="40"> |
|
72 |
<td><a href="images/1,2,3">Ver sobre el mapa</a></tr></table><hr width ="70%"> |
|
73 |
<table> |
|
74 |
<tr> |
|
75 |
<td width="40"><img src="images/turn-right.png" width="32" height="32"></td> |
|
76 |
<td class='normal'>4 Contin?e por <b>LA ALBERCA</b> durante 355.99 y gire |
|
77 |
a la <span class="right"><b>derecha</b></span> por <b>SOMONTES</b></td> |
|
78 |
</tr><tr> |
|
79 |
<td width="40"> </td> |
|
80 |
<td class="distancia">Distancia acumulada: 3,124.01</td> |
|
81 |
</tr><tr> |
|
82 |
<td width="40"> |
|
83 |
<td><a href="images/4,5,6">Ver sobre el mapa</a></tr></table> |
|
84 |
<hr width ="70%"> |
|
85 |
<table> |
|
86 |
<tr> |
|
87 |
<td width="40"><img src="images/drapeau_arrivee.gif" width="18" height="26"></td> |
|
88 |
<td class="resumen">16. Llegada: MONTE CARMELO</td> |
|
89 |
</tr><tr> |
|
90 |
<td width="40"> </td> |
|
91 |
<td class="distancia">Longitud: 9,020.31</td> |
|
92 |
</tr><tr> |
|
93 |
<td width="40"> |
|
94 |
<td><a href="images/24">Ver sobre el mapa</a></tr></table> |
|
95 |
</body> |
|
96 |
</html> |
|
0 | 97 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/algorithms/SnapPointLocator.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 06-oct-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 |
* Revision 1.1 2006-10-17 18:25:53 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* Revision 1.1 2006/10/09 19:10:56 azabala |
|
52 |
* First version in CVS |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
package com.vividsolutions.jts.algorithms; |
|
57 |
|
|
58 |
import java.util.Iterator; |
|
59 |
|
|
60 |
|
|
61 |
import com.vividsolutions.jts.geom.Coordinate; |
|
62 |
import com.vividsolutions.jts.geom.Geometry; |
|
63 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
64 |
import com.vividsolutions.jts.geom.GeometryCollectionIterator; |
|
65 |
import com.vividsolutions.jts.geom.LineString; |
|
66 |
import com.vividsolutions.jts.geom.LinearRing; |
|
67 |
import com.vividsolutions.jts.geom.Location; |
|
68 |
import com.vividsolutions.jts.geom.MultiLineString; |
|
69 |
import com.vividsolutions.jts.geom.MultiPolygon; |
|
70 |
import com.vividsolutions.jts.geom.Polygon; |
|
71 |
import com.vividsolutions.jts.geomgraph.SnappingGeometryGraph; |
|
72 |
|
|
73 |
public class SnapPointLocator extends com.vividsolutions.jts.algorithm.PointLocator { |
|
74 |
private boolean isIn; // true if the point lies in or on any Geometry element |
|
75 |
private int numBoundaries; // the number of sub-elements whose boundaries the point lies in |
|
76 |
|
|
77 |
public SnapPointLocator() { |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Convenience method to test a point for intersection with |
|
82 |
* a Geometry |
|
83 |
* @param p the coordinate to test |
|
84 |
* @param geom the Geometry to test |
|
85 |
* @return <code>true</code> if the point is in the interior or boundary of the Geometry |
|
86 |
*/ |
|
87 |
public boolean intersects(Coordinate p, Geometry geom, double snapTolerance) |
|
88 |
{ |
|
89 |
return locate(p, geom, snapTolerance) != Location.EXTERIOR; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Computes the topological relationship ({@link Location}) of a single point |
|
94 |
* to a Geometry. |
|
95 |
* It handles both single-element |
|
96 |
* and multi-element Geometries. |
|
97 |
* The algorithm for multi-part Geometries |
|
98 |
* takes into account the SFS Boundary Determination Rule. |
|
99 |
* |
|
100 |
* @return the {@link Location} of the point relative to the input Geometry |
|
101 |
*/ |
|
102 |
public int locate(Coordinate p, Geometry geom, double snapTolerance) |
|
103 |
{ |
|
104 |
if (geom.isEmpty()) return Location.EXTERIOR; |
|
105 |
|
|
106 |
if (geom instanceof LinearRing) { |
|
107 |
return locate(p, (LinearRing) geom, snapTolerance); |
|
108 |
} |
|
109 |
if (geom instanceof LineString) { |
|
110 |
return locate(p, (LineString) geom, snapTolerance); |
|
111 |
} |
|
112 |
else if (geom instanceof Polygon) { |
|
113 |
return locate(p, (Polygon) geom, snapTolerance); |
|
114 |
} |
|
115 |
|
|
116 |
isIn = false; |
|
117 |
numBoundaries = 0; |
|
118 |
computeLocation(p, geom, snapTolerance); |
|
119 |
if (SnappingGeometryGraph.isInBoundary(numBoundaries)) |
|
120 |
return Location.BOUNDARY; |
|
121 |
if (numBoundaries > 0 || isIn) |
|
122 |
return Location.INTERIOR; |
|
123 |
return Location.EXTERIOR; |
|
124 |
} |
|
125 |
|
|
126 |
private void computeLocation(Coordinate p, Geometry geom, double snapTolerance) |
|
127 |
{ |
|
128 |
if (geom instanceof LinearRing) { |
|
129 |
updateLocationInfo(locate(p, (LinearRing) geom, snapTolerance)); |
|
130 |
} |
|
131 |
if (geom instanceof LineString) { |
|
132 |
updateLocationInfo(locate(p, (LineString) geom, snapTolerance)); |
|
133 |
} |
|
134 |
else if (geom instanceof Polygon) { |
|
135 |
updateLocationInfo(locate(p, (Polygon) geom, snapTolerance)); |
|
136 |
} |
|
137 |
else if (geom instanceof MultiLineString) { |
|
138 |
MultiLineString ml = (MultiLineString) geom; |
|
139 |
for (int i = 0; i < ml.getNumGeometries(); i++) { |
|
140 |
LineString l = (LineString) ml.getGeometryN(i); |
|
141 |
updateLocationInfo(locate(p, l, snapTolerance)); |
|
142 |
} |
|
143 |
} |
|
144 |
else if (geom instanceof MultiPolygon) { |
|
145 |
MultiPolygon mpoly = (MultiPolygon) geom; |
|
146 |
for (int i = 0; i < mpoly.getNumGeometries(); i++) { |
|
147 |
Polygon poly = (Polygon) mpoly.getGeometryN(i); |
|
148 |
updateLocationInfo(locate(p, poly, snapTolerance)); |
|
149 |
} |
|
150 |
} |
|
151 |
else if (geom instanceof GeometryCollection) { |
|
152 |
Iterator geomi = new GeometryCollectionIterator((GeometryCollection) geom); |
|
153 |
while (geomi.hasNext()) { |
|
154 |
Geometry g2 = (Geometry) geomi.next(); |
|
155 |
if (g2 != geom) |
|
156 |
computeLocation(p, g2, snapTolerance); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
private void updateLocationInfo(int loc) |
|
162 |
{ |
|
163 |
if (loc == Location.INTERIOR) isIn = true; |
|
164 |
if (loc == Location.BOUNDARY) numBoundaries++; |
|
165 |
} |
|
166 |
|
|
167 |
private int locate(Coordinate p, LineString l, double snapTolerance) |
|
168 |
{ |
|
169 |
Coordinate[] pt = l.getCoordinates(); |
|
170 |
if (! l.isClosed()) { |
|
171 |
if (p.distance(pt[0]) <= snapTolerance |
|
172 |
|| p.distance(pt[pt.length - 1]) <= snapTolerance ) { |
|
173 |
return Location.BOUNDARY; |
|
174 |
} |
|
175 |
} |
|
176 |
if (SnapCGAlgorithms.isOnLine(p, pt, snapTolerance)) |
|
177 |
return Location.INTERIOR; |
|
178 |
return Location.EXTERIOR; |
|
179 |
} |
|
180 |
|
|
181 |
private int locate(Coordinate p, LinearRing ring, double snapTolerance) |
|
182 |
{ |
|
183 |
// can this test be folded into isPointInRing ? |
|
184 |
if (SnapCGAlgorithms.isOnLine(p, ring.getCoordinates())) { |
|
185 |
return Location.BOUNDARY; |
|
186 |
} |
|
187 |
if (SnapCGAlgorithms.isPointInRing(p, ring.getCoordinates(), snapTolerance)) |
|
188 |
return Location.INTERIOR; |
|
189 |
return Location.EXTERIOR; |
|
190 |
} |
|
191 |
|
|
192 |
private int locate(Coordinate p, Polygon poly, double snapTolerance) |
|
193 |
{ |
|
194 |
if (poly.isEmpty()) return Location.EXTERIOR; |
|
195 |
LinearRing shell = (LinearRing) poly.getExteriorRing(); |
|
196 |
|
|
197 |
int shellLoc = locate(p, shell, snapTolerance); |
|
198 |
if (shellLoc == Location.EXTERIOR) return Location.EXTERIOR; |
|
199 |
if (shellLoc == Location.BOUNDARY) return Location.BOUNDARY; |
|
200 |
// now test if the point lies in or on the holes |
|
201 |
for (int i = 0; i < poly.getNumInteriorRing(); i++) { |
|
202 |
LinearRing hole = (LinearRing) poly.getInteriorRingN(i); |
|
203 |
int holeLoc = locate(p, hole, snapTolerance); |
|
204 |
if (holeLoc == Location.INTERIOR) return Location.EXTERIOR; |
|
205 |
if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY; |
|
206 |
} |
|
207 |
return Location.INTERIOR; |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
0 | 211 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/algorithms/SnapCGAlgorithms.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 06-oct-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 |
* Revision 1.2 2006-10-19 16:06:48 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* Revision 1.1 2006/10/17 18:25:53 azabala |
|
52 |
* *** empty log message *** |
|
53 |
* |
|
54 |
* Revision 1.1 2006/10/09 19:10:56 azabala |
|
55 |
* First version in CVS |
|
56 |
* |
|
57 |
* |
|
58 |
*/ |
|
59 |
package com.vividsolutions.jts.algorithms; |
|
60 |
|
|
61 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
|
62 |
import com.vividsolutions.jts.algorithm.RobustDeterminant; |
|
63 |
import com.vividsolutions.jts.geom.Coordinate; |
|
64 |
import com.vividsolutions.jts.operation.overlay.SnapLineIntersector; |
|
65 |
|
|
66 |
public class SnapCGAlgorithms extends CGAlgorithms { |
|
67 |
/** |
|
68 |
* Test whether a point lies on the line segments defined by a |
|
69 |
* list of coordinates. |
|
70 |
* |
|
71 |
* @return true true if |
|
72 |
* the point is a vertex of the line or lies in the interior of a line |
|
73 |
* segment in the linestring |
|
74 |
*/ |
|
75 |
public static boolean isOnLine(Coordinate p, Coordinate[] pt, double snapTol) { |
|
76 |
SnapLineIntersector lineIntersector = new SnapLineIntersector(snapTol); |
|
77 |
for (int i = 1; i < pt.length; i++) { |
|
78 |
Coordinate p0 = pt[i - 1]; |
|
79 |
Coordinate p1 = pt[i]; |
|
80 |
lineIntersector.computeIntersection(p, p0, p1); |
|
81 |
if (lineIntersector.hasIntersection()) { |
|
82 |
return true; |
|
83 |
} |
|
84 |
} |
|
85 |
return false; |
|
86 |
} |
|
87 |
public static boolean isPointInRing(Coordinate p, Coordinate[] ring, double snapTolerance) { |
|
88 |
/* |
|
89 |
* For each segment l = (i-1, i), see if it crosses ray from test point in positive x direction. |
|
90 |
*/ |
|
91 |
int crossings = 0; // number of segment/ray crossings |
|
92 |
|
|
93 |
SnapLineIntersector lineIntersector = new SnapLineIntersector(snapTolerance); |
|
94 |
|
|
95 |
for (int i = 1; i < ring.length; i++) { |
|
96 |
int i1 = i - 1; |
|
97 |
Coordinate p1 = ring[i]; |
|
98 |
Coordinate p2 = ring[i1]; |
|
99 |
|
|
100 |
lineIntersector.computeIntersection(p, p1, p2); |
|
101 |
if (lineIntersector.hasIntersection()) { |
|
102 |
crossings ++; |
|
103 |
} |
|
104 |
|
|
105 |
// if (((p1.y > (p.y - snapTolerance)) && (p2.y <= (p.y + snapTolerance))) || |
|
106 |
// ((p2.y > (p.y - snapTolerance)) && (p1.y <= (p.y) + snapTolerance))) {//si no se cumple, no pueden intersectar |
|
107 |
// |
|
108 |
// double x1 = p1.x - p.x; |
|
109 |
// double y1 = p1.y - p.y; |
|
110 |
// double x2 = p2.x - p.x; |
|
111 |
// double y2 = p2.y - p.y; |
|
112 |
// /* |
|
113 |
// * segment straddles x axis, so compute intersection with x-axis. |
|
114 |
// */ |
|
115 |
// double xInt = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2) / (y2 - y1); |
|
116 |
// //xsave = xInt; |
|
117 |
// /* |
|
118 |
// * crosses ray if strictly positive intersection. |
|
119 |
// */ |
|
120 |
// if (xInt > 0.0) { |
|
121 |
// crossings++; |
|
122 |
// } |
|
123 |
// } |
|
124 |
} |
|
125 |
/* |
|
126 |
* p is inside if number of crossings is odd. |
|
127 |
*/ |
|
128 |
if ((crossings % 2) == 1) { |
|
129 |
return true; |
|
130 |
} |
|
131 |
else { |
|
132 |
return false; |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Computes the orientation of a point q to the directed line segment p1-p2. |
|
138 |
* The orientation of a point relative to a directed line segment indicates |
|
139 |
* which way you turn to get to q after travelling from p1 to p2. |
|
140 |
* |
|
141 |
* @return 1 if q is counter-clockwise from p1-p2 |
|
142 |
* @return -1 if q is clockwise from p1-p2 |
|
143 |
* @return 0 if q is collinear with p1-p2 |
|
144 |
*/ |
|
145 |
public static int computeOrientation(Coordinate p1, Coordinate p2, Coordinate q) { |
|
146 |
return orientationIndex(p1, p2, q); |
|
147 |
} |
|
148 |
/** |
|
149 |
* Returns the index of the direction of the point <code>q</code> |
|
150 |
* relative to a |
|
151 |
* vector specified by <code>p1-p2</code>. |
|
152 |
* |
|
153 |
* @param p1 the origin point of the vector |
|
154 |
* @param p2 the final point of the vector |
|
155 |
* @param q the point to compute the direction to |
|
156 |
* |
|
157 |
* @return 1 if q is counter-clockwise (left) from p1-p2 |
|
158 |
* @return -1 if q is clockwise (right) from p1-p2 |
|
159 |
* @return 0 if q is collinear with p1-p2 |
|
160 |
*/ |
|
161 |
public static int orientationIndex(Coordinate p1, Coordinate p2, Coordinate q) { |
|
162 |
// travelling along p1->p2, turn counter clockwise to get to q return 1, |
|
163 |
// travelling along p1->p2, turn clockwise to get to q return -1, |
|
164 |
// p1, p2 and q are colinear return 0. |
|
165 |
double dx1 = p2.x - p1.x; |
|
166 |
double dy1 = p2.y - p1.y; |
|
167 |
double dx2 = q.x - p2.x; |
|
168 |
double dy2 = q.y - p2.y; |
|
169 |
return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2); |
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 |
} |
|
174 |
|
|
0 | 175 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/algorithms/SnapSimplePointInAreaLocator.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 06-oct-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 |
* Revision 1.1 2006-10-17 18:25:53 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* Revision 1.1 2006/10/09 19:10:56 azabala |
|
52 |
* First version in CVS |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
package com.vividsolutions.jts.algorithms; |
|
57 |
|
|
58 |
import java.util.Iterator; |
|
59 |
|
|
60 |
|
|
61 |
import com.vividsolutions.jts.geom.Coordinate; |
|
62 |
import com.vividsolutions.jts.geom.Geometry; |
|
63 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
64 |
import com.vividsolutions.jts.geom.GeometryCollectionIterator; |
|
65 |
import com.vividsolutions.jts.geom.LinearRing; |
|
66 |
import com.vividsolutions.jts.geom.Location; |
|
67 |
import com.vividsolutions.jts.geom.Polygon; |
|
68 |
|
|
69 |
public class SnapSimplePointInAreaLocator extends |
|
70 |
com.vividsolutions.jts.algorithm.SimplePointInAreaLocator { |
|
71 |
public static int locate(Coordinate p, Geometry geom, double snapTolerance) |
|
72 |
{ |
|
73 |
if (geom.isEmpty()) return Location.EXTERIOR; |
|
74 |
|
|
75 |
if (containsPoint(p, geom, snapTolerance)) |
|
76 |
return Location.INTERIOR; |
|
77 |
return Location.EXTERIOR; |
|
78 |
} |
|
79 |
|
|
80 |
private static boolean containsPoint(Coordinate p, Geometry geom, double snapTolerance) |
|
81 |
{ |
|
82 |
if (geom instanceof Polygon) { |
|
83 |
return containsPointInPolygon(p, (Polygon) geom); |
|
84 |
} |
|
85 |
else if (geom instanceof GeometryCollection) { |
|
86 |
Iterator geomi = new GeometryCollectionIterator((GeometryCollection) geom); |
|
87 |
while (geomi.hasNext()) { |
|
88 |
Geometry g2 = (Geometry) geomi.next(); |
|
89 |
if (g2 != geom) |
|
90 |
if (containsPoint(p, g2, snapTolerance)) |
|
91 |
return true; |
|
92 |
} |
|
93 |
} |
|
94 |
return false; |
|
95 |
} |
|
96 |
|
|
97 |
public static boolean containsPointInPolygon(Coordinate p, Polygon poly, double snapTolerance) |
|
98 |
{ |
|
99 |
if (poly.isEmpty()) return false; |
|
100 |
LinearRing shell = (LinearRing) poly.getExteriorRing(); |
|
101 |
if (! SnapCGAlgorithms.isPointInRing(p, shell.getCoordinates(), snapTolerance)) return false; |
|
102 |
// now test if the point lies in or on the holes |
|
103 |
for (int i = 0; i < poly.getNumInteriorRing(); i++) { |
|
104 |
LinearRing hole = (LinearRing) poly.getInteriorRingN(i); |
|
105 |
if (SnapCGAlgorithms.isPointInRing(p, hole.getCoordinates(), snapTolerance)) return false; |
|
106 |
} |
|
107 |
return true; |
|
108 |
} |
|
109 |
|
|
110 |
} |
|
111 |
|
|
0 | 112 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/geomgraph/SnapDirectedEdge.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 02-oct-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 |
* Revision 1.1 2006-10-17 18:25:53 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* Revision 1.2 2006/10/09 19:10:56 azabala |
|
52 |
* First version in CVS |
|
53 |
* |
|
54 |
* Revision 1.1 2006/10/05 19:20:57 azabala |
|
55 |
* first version in cvs |
|
56 |
* |
|
57 |
* Revision 1.1 2006/10/02 19:06:39 azabala |
|
58 |
* *** empty log message *** |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
package com.vividsolutions.jts.geomgraph; |
|
63 |
|
|
64 |
import com.vividsolutions.jts.algorithms.SnapCGAlgorithms; |
|
65 |
import com.vividsolutions.jts.geom.Coordinate; |
|
66 |
import com.vividsolutions.jts.geomgraph.DirectedEdge; |
|
67 |
import com.vividsolutions.jts.geomgraph.Edge; |
|
68 |
import com.vividsolutions.jts.geomgraph.Quadrant; |
|
69 |
import com.vividsolutions.jts.util.Assert; |
|
70 |
|
|
71 |
public class SnapDirectedEdge extends DirectedEdge { |
|
72 |
|
|
73 |
private Coordinate p0; |
|
74 |
private Coordinate p1; |
|
75 |
private double dx, dy; |
|
76 |
int quadrant; |
|
77 |
|
|
78 |
public SnapDirectedEdge(Edge arg0, boolean arg1) { |
|
79 |
super(arg0, arg1); |
|
80 |
} |
|
81 |
|
|
82 |
public Coordinate getCoordinate() { return p0; } |
|
83 |
public Coordinate getDirectedCoordinate() { return p1; } |
|
84 |
public int getQuadrant() { return quadrant; } |
|
85 |
public double getDx() { return dx; } |
|
86 |
public double getDy() { return dy; } |
|
87 |
|
|
88 |
protected void init(Coordinate p0, Coordinate p1) |
|
89 |
{ |
|
90 |
this.p0 = p0; |
|
91 |
this.p1 = p1; |
|
92 |
dx = p1.x - p0.x; |
|
93 |
dy = p1.y - p0.y; |
|
94 |
if(dx == 0 && dy == 0) |
|
95 |
System.out.println(p0.toString()+";"+p1.toString()); |
|
96 |
quadrant = Quadrant.quadrant(dx, dy); |
|
97 |
|
|
98 |
Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found"); |
|
99 |
} |
|
100 |
|
|
101 |
public String toString(){ |
|
102 |
return this.p0.toString() + "," + p1.toString(); |
|
103 |
} |
|
104 |
|
|
105 |
public int compareTo(Object obj) |
|
106 |
{ |
|
107 |
SnapDirectedEdge de = (SnapDirectedEdge) obj; |
|
108 |
return compareDirection(de); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Returns 1 if this DirectedEdge has a greater angle with the |
|
113 |
* positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise. |
|
114 |
* <p> |
|
115 |
* Using the obvious algorithm of simply computing the angle is not robust, |
|
116 |
* since the angle calculation is susceptible to roundoff. A robust algorithm |
|
117 |
* is: |
|
118 |
* <ul> |
|
119 |
* <li>first compare the quadrants. If the quadrants are different, it it |
|
120 |
* trivial to determine which vector is "greater". |
|
121 |
* <li>if the vectors lie in the same quadrant, the robust |
|
122 |
* {@link RobustCGAlgorithms#computeOrientation(Coordinate, Coordinate, Coordinate)} |
|
123 |
* function can be used to decide the relative orientation of the vectors. |
|
124 |
* </ul> |
|
125 |
*/ |
|
126 |
public int compareDirection(SnapDirectedEdge e) |
|
127 |
{ |
|
128 |
// if the rays are in different quadrants, determining the ordering is trivial |
|
129 |
if (quadrant > e.quadrant) return 1; |
|
130 |
if (quadrant < e.quadrant) return -1; |
|
131 |
// vectors are in the same quadrant - check relative orientation of direction vectors |
|
132 |
// this is > e if it is CCW of e |
|
133 |
return SnapCGAlgorithms.computeOrientation(e.p0, e.p1, p1); |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
} |
|
138 |
|
|
0 | 139 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/geomgraph/SnapEdgeIntersection.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 02-oct-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 |
* Revision 1.1 2006-10-17 18:25:53 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* Revision 1.1 2006/10/05 19:20:57 azabala |
|
52 |
* first version in cvs |
|
53 |
* |
|
54 |
* Revision 1.1 2006/10/02 19:06:39 azabala |
|
55 |
* *** empty log message *** |
|
56 |
* |
|
57 |
* |
|
58 |
*/ |
|
59 |
package com.vividsolutions.jts.geomgraph; |
|
60 |
|
|
61 |
import com.vividsolutions.jts.geom.Coordinate; |
|
62 |
import com.vividsolutions.jts.geomgraph.EdgeIntersection; |
|
63 |
|
|
64 |
public class SnapEdgeIntersection extends EdgeIntersection { |
|
65 |
|
|
66 |
|
|
67 |
public SnapEdgeIntersection(Coordinate coord, int segmentIndex, double dist) { |
|
68 |
super(coord, segmentIndex, dist); |
|
69 |
} |
|
70 |
|
|
71 |
public int compareTo(Object obj) |
|
72 |
{ |
|
73 |
SnapEdgeIntersection other = (SnapEdgeIntersection) obj; |
|
74 |
return compare(other.segmentIndex, other.dist); |
|
75 |
} |
|
76 |
/** |
|
77 |
* @return -1 this EdgeIntersection is located before the argument location |
|
78 |
* @return 0 this EdgeIntersection is at the argument location |
|
79 |
* @return 1 this EdgeIntersection is located after the argument location |
|
80 |
*/ |
|
81 |
public int compare(int segmentIndex, double dist) |
|
82 |
{ |
|
83 |
//TODO VER SI METER DISTANCIA DE SNAP |
|
84 |
if (this.segmentIndex < segmentIndex) return -1; |
|
85 |
if (this.segmentIndex > segmentIndex) return 1; |
|
86 |
if (this.dist < dist) return -1; |
|
87 |
if (this.dist > dist) return 1; |
|
88 |
return 0; |
|
89 |
} |
|
90 |
|
|
91 |
public boolean isEndPoint(int maxSegmentIndex) |
|
92 |
{ |
|
93 |
//TODO VER SI METER DISTANCIA DE SNAP |
|
94 |
if (segmentIndex == 0 && dist == 0.0) return true; |
|
95 |
if (segmentIndex == maxSegmentIndex) return true; |
|
96 |
return false; |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
0 | 100 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/geomgraph/SnappingGeometryGraph.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 12-sep-2006 by azabala |
|
3 |
* |
|
4 |
*/ |
|
5 |
package com.vividsolutions.jts.geomgraph; |
|
6 |
|
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.Collection; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.Iterator; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
|
15 |
import com.vividsolutions.jts.algorithm.LineIntersector; |
|
16 |
import com.vividsolutions.jts.geom.*; |
|
17 |
import com.vividsolutions.jts.geomgraph.index.SegmentIntersector; |
|
18 |
import com.vividsolutions.jts.geomgraph.index.SimpleMCSweepLineIntersector; |
|
19 |
import com.vividsolutions.jts.geomgraph.index.SnapSimpleMCSweepLineIntersector; |
|
20 |
import com.vividsolutions.jts.util.Assert; |
|
21 |
|
|
22 |
/** |
|
23 |
*/ |
|
24 |
public class SnappingGeometryGraph extends GeometryGraph { |
|
25 |
|
|
26 |
// Properties of PlanarGraph that we want to overwrite to |
|
27 |
// use snapping |
|
28 |
public static final CGAlgorithms cga = new CGAlgorithms(); |
|
29 |
|
|
30 |
protected SnappingNodeMap nodes; |
|
31 |
|
|
32 |
|
|
33 |
// overwrite to catch them when returned by Snapping map |
|
34 |
protected Collection boundaryNodes; |
|
35 |
|
|
36 |
protected int argIndex; |
|
37 |
|
|
38 |
private boolean useBoundaryDeterminationRule = false; |
|
39 |
|
|
40 |
private boolean hasTooFewPoints = false; |
|
41 |
|
|
42 |
private Coordinate invalidPoint; |
|
43 |
|
|
44 |
private Map lineEdgeMap = new HashMap(); |
|
45 |
|
|
46 |
private Geometry parentGeometry; |
|
47 |
|
|
48 |
double snapTolerance; |
|
49 |
|
|
50 |
public SnappingGeometryGraph(NodeFactory nodeFact, double tolerance, |
|
51 |
int argIndex, Geometry parentGeometry) { |
|
52 |
//le pasamos al constructor padre GeometryCollection vacia para que |
|
53 |
//no replique la construccion del grafo |
|
54 |
super(argIndex, new GeometryCollection(new Geometry[0], parentGeometry.getFactory())); |
|
55 |
nodes = new SnappingNodeMap(nodeFact, tolerance); |
|
56 |
this.argIndex = argIndex; |
|
57 |
this.parentGeometry = parentGeometry; |
|
58 |
this.snapTolerance = tolerance; |
|
59 |
add(parentGeometry); |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
public Geometry getGeometry(){ |
|
64 |
return this.parentGeometry; |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
public void dumpNodes(){ |
|
69 |
this.nodes.dump(); |
|
70 |
} |
|
71 |
|
|
72 |
public SnappingGeometryGraph(double tolerance, int argIndex, Geometry parent) { |
|
73 |
super(argIndex, new GeometryCollection(new Geometry[0], parent.getFactory())); |
|
74 |
nodes = new SnappingNodeMap(new NodeFactory(), tolerance); |
|
75 |
this.argIndex = argIndex; |
|
76 |
this.snapTolerance = tolerance; |
|
77 |
this.parentGeometry = parent; |
|
78 |
add(parent); |
|
79 |
} |
|
80 |
|
|
81 |
public Collection getBoundaryNodes() { |
|
82 |
if (boundaryNodes == null) |
|
83 |
boundaryNodes = nodes.getBoundaryNodes(argIndex); |
|
84 |
return boundaryNodes; |
|
85 |
} |
|
86 |
|
|
87 |
public Coordinate[] getBoundaryPoints() { |
|
88 |
Collection coll = getBoundaryNodes(); |
|
89 |
Coordinate[] pts = new Coordinate[coll.size()]; |
|
90 |
int i = 0; |
|
91 |
for (Iterator it = coll.iterator(); it.hasNext();) { |
|
92 |
Node node = (Node) it.next(); |
|
93 |
pts[i++] = (Coordinate) node.getCoordinate().clone(); |
|
94 |
} |
|
95 |
return pts; |
|
96 |
} |
|
97 |
|
|
98 |
public Iterator getNodeIterator() { |
|
99 |
return nodes.iterator(); |
|
100 |
} |
|
101 |
|
|
102 |
public Collection getNodes() { |
|
103 |
return nodes.values(); |
|
104 |
} |
|
105 |
|
|
106 |
public Node addNode(Node node) { |
|
107 |
return nodes.addNode(node); |
|
108 |
} |
|
109 |
|
|
110 |
public Node addNode(Coordinate coord) { |
|
111 |
return nodes.addNode(coord); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* @return the node if found; null otherwise |
|
116 |
*/ |
|
117 |
public Node find(Coordinate coord) { |
|
118 |
return nodes.find(coord); |
|
119 |
} |
|
120 |
|
|
121 |
public boolean isBoundaryNode(int geomIndex, Coordinate coord) { |
|
122 |
Node node = nodes.find(coord); |
|
123 |
if (node == null) |
|
124 |
return false; |
|
125 |
Label label = node.getLabel(); |
|
126 |
if (label != null && label.getLocation(geomIndex) == Location.BOUNDARY) |
|
127 |
return true; |
|
128 |
return false; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
public void add(EdgeEnd e) { |
|
134 |
nodes.add(e); |
|
135 |
edgeEndList.add(e); |
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* Link the DirectedEdges at the nodes of the graph. This allows clients to |
|
142 |
* link only a subset of nodes in the graph, for efficiency (because they |
|
143 |
* know that only a subset is of interest). |
|
144 |
*/ |
|
145 |
public void linkResultDirectedEdges() { |
|
146 |
for (Iterator nodeit = nodes.iterator(); nodeit.hasNext();) { |
|
147 |
Node node = (Node) nodeit.next(); |
|
148 |
((DirectedEdgeStar) node.getEdges()).linkResultDirectedEdges(); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Link the DirectedEdges at the nodes of the graph. This allows clients to |
|
154 |
* link only a subset of nodes in the graph, for efficiency (because they |
|
155 |
* know that only a subset is of interest). |
|
156 |
*/ |
|
157 |
public void linkAllDirectedEdges() { |
|
158 |
for (Iterator nodeit = nodes.iterator(); nodeit.hasNext();) { |
|
159 |
Node node = (Node) nodeit.next(); |
|
160 |
((DirectedEdgeStar) node.getEdges()).linkAllDirectedEdges(); |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Returns the EdgeEnd which has edge e as its base edge (MD 18 Feb 2002 - |
|
166 |
* this should return a pair of edges) |
|
167 |
* |
|
168 |
* @return the edge, if found <code>null</code> if the edge was not found |
|
169 |
*/ |
|
170 |
public EdgeEnd findEdgeEnd(Edge e) { |
|
171 |
for (Iterator i = getEdgeEnds().iterator(); i.hasNext();) { |
|
172 |
EdgeEnd ee = (EdgeEnd) i.next(); |
|
173 |
if (ee.getEdge() == e) |
|
174 |
return ee; |
|
175 |
} |
|
176 |
return null; |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* Returns the edge whose first two coordinates are p0 and p1 |
|
181 |
* |
|
182 |
* @return the edge, if found <code>null</code> if the edge was not found |
|
183 |
*/ |
|
184 |
public Edge findEdge(Coordinate p0, Coordinate p1) { |
|
185 |
for (int i = 0; i < edges.size(); i++) { |
|
186 |
Edge e = (Edge) edges.get(i); |
|
187 |
Coordinate[] eCoord = e.getCoordinates(); |
|
188 |
if (p0.equals(eCoord[0]) && p1.equals(eCoord[1])) |
|
189 |
return e; |
|
190 |
} |
|
191 |
return null; |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Returns the edge which starts at p0 and whose first segment is parallel |
|
196 |
* to p1 |
|
197 |
* |
|
198 |
* @return the edge, if found <code>null</code> if the edge was not found |
|
199 |
*/ |
|
200 |
public Edge findEdgeInSameDirection(Coordinate p0, Coordinate p1) { |
|
201 |
for (int i = 0; i < edges.size(); i++) { |
|
202 |
Edge e = (Edge) edges.get(i); |
|
203 |
|
|
204 |
Coordinate[] eCoord = e.getCoordinates(); |
|
205 |
if (matchInSameDirection(p0, p1, eCoord[0], eCoord[1])) |
|
206 |
return e; |
|
207 |
|
|
208 |
if (matchInSameDirection(p0, p1, eCoord[eCoord.length - 1], |
|
209 |
eCoord[eCoord.length - 2])) |
|
210 |
return e; |
|
211 |
} |
|
212 |
return null; |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* The coordinate pairs match if they define line segments lying in the same |
|
217 |
* direction. E.g. the segments are parallel and in the same quadrant (as |
|
218 |
* opposed to parallel and opposite!). |
|
219 |
*/ |
|
220 |
private boolean matchInSameDirection(Coordinate p0, Coordinate p1, |
|
221 |
Coordinate ep0, Coordinate ep1) { |
|
222 |
if (!p0.equals(ep0)) |
|
223 |
return false; |
|
224 |
|
|
225 |
if (CGAlgorithms.computeOrientation(p0, p1, ep1) == CGAlgorithms.COLLINEAR |
|
226 |
&& Quadrant.quadrant(p0, p1) == Quadrant.quadrant(ep0, ep1)) |
|
227 |
return true; |
|
228 |
return false; |
|
229 |
} |
|
230 |
|
|
231 |
|
|
232 |
private void add(Geometry g) |
|
233 |
{ |
|
234 |
if (g.isEmpty()) return; |
|
235 |
|
|
236 |
// check if this Geometry should obey the Boundary Determination Rule |
|
237 |
// all collections except MultiPolygons obey the rule |
|
238 |
if (g instanceof GeometryCollection |
|
239 |
&& ! (g instanceof MultiPolygon)) |
|
240 |
useBoundaryDeterminationRule = true; |
|
241 |
|
|
242 |
if (g instanceof Polygon) addPolygon((Polygon) g); |
|
243 |
// LineString also handles LinearRings |
|
244 |
else if (g instanceof LineString) addLineString((LineString) g); |
|
245 |
else if (g instanceof Point) addPoint((Point) g); |
|
246 |
else if (g instanceof MultiPoint) addCollection((MultiPoint) g); |
|
247 |
else if (g instanceof MultiLineString) addCollection((MultiLineString) g); |
|
248 |
else if (g instanceof MultiPolygon) addCollection((MultiPolygon) g); |
|
249 |
else if (g instanceof GeometryCollection) addCollection((GeometryCollection) g); |
|
250 |
else throw new UnsupportedOperationException(g.getClass().getName()); |
|
251 |
} |
|
252 |
|
|
253 |
private void addCollection(GeometryCollection gc) |
|
254 |
{ |
|
255 |
for (int i = 0; i < gc.getNumGeometries(); i++) { |
|
256 |
Geometry g = gc.getGeometryN(i); |
|
257 |
add(g); |
|
258 |
} |
|
259 |
} |
|
260 |
/** |
|
261 |
* Add a Point to the graph. |
|
262 |
*/ |
|
263 |
private void addPoint(Point p) |
|
264 |
{ |
|
265 |
Coordinate coord = p.getCoordinate(); |
|
266 |
insertPoint(argIndex, coord, Location.INTERIOR); |
|
267 |
} |
|
268 |
/** |
|
269 |
* The left and right topological location arguments assume that the ring is oriented CW. |
|
270 |
* If the ring is in the opposite orientation, |
|
271 |
* the left and right locations must be interchanged. |
|
272 |
*/ |
|
273 |
private void addPolygonRing(LinearRing lr, int cwLeft, int cwRight) |
|
274 |
{ |
|
275 |
Coordinate[] coord = CoordinateArrays.removeRepeatedPoints(lr.getCoordinates()); |
|
276 |
|
|
277 |
if (coord.length < 4) { |
|
278 |
hasTooFewPoints = true; |
|
279 |
invalidPoint = coord[0]; |
|
280 |
return; |
|
281 |
} |
|
282 |
|
|
283 |
int left = cwLeft; |
|
284 |
int right = cwRight; |
|
285 |
if (cga.isCCW(coord)) { |
|
286 |
left = cwRight; |
|
287 |
right = cwLeft; |
|
288 |
} |
|
289 |
SnappingEdge e = new SnappingEdge(coord, |
|
290 |
new Label(argIndex, Location.BOUNDARY, left, right), this.snapTolerance); |
|
291 |
lineEdgeMap.put(lr, e); |
|
292 |
|
|
293 |
insertEdge(e); |
|
294 |
// insert the endpoint as a node, to mark that it is on the boundary |
|
295 |
insertPoint(argIndex, coord[0], Location.BOUNDARY); |
|
296 |
} |
|
297 |
|
|
298 |
private void addPolygon(Polygon p) |
|
299 |
{ |
|
300 |
addPolygonRing( |
|
301 |
(LinearRing) p.getExteriorRing(), |
|
302 |
Location.EXTERIOR, |
|
303 |
Location.INTERIOR); |
|
304 |
|
|
305 |
for (int i = 0; i < p.getNumInteriorRing(); i++) { |
|
306 |
// Holes are topologically labelled opposite to the shell, since |
|
307 |
// the interior of the polygon lies on their opposite side |
|
308 |
// (on the left, if the hole is oriented CW) |
|
309 |
addPolygonRing( |
|
310 |
(LinearRing) p.getInteriorRingN(i), |
|
311 |
Location.INTERIOR, |
|
312 |
Location.EXTERIOR); |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
private void addLineString(LineString line) |
|
317 |
{ |
|
318 |
Coordinate[] coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates()); |
|
319 |
|
|
320 |
if (coord.length < 2) { |
|
321 |
hasTooFewPoints = true; |
|
322 |
invalidPoint = coord[0]; |
|
323 |
return; |
|
324 |
} |
|
325 |
|
|
326 |
// add the edge for the LineString |
|
327 |
// line edges do not have locations for their left and right sides |
|
328 |
SnappingEdge e = new SnappingEdge(coord, new Label(argIndex, Location.INTERIOR) , this.snapTolerance); |
|
329 |
lineEdgeMap.put(line, e); |
|
330 |
insertEdge(e); |
|
331 |
/** |
|
332 |
* Add the boundary points of the LineString, if any. |
|
333 |
* Even if the LineString is closed, add both points as if they were endpoints. |
|
334 |
* This allows for the case that the node already exists and is a boundary point. |
|
335 |
*/ |
|
336 |
Assert.isTrue(coord.length >= 2, "found LineString with single point"); |
|
337 |
insertBoundaryPoint(argIndex, coord[0]); |
|
338 |
insertBoundaryPoint(argIndex, coord[coord.length - 1]); |
|
339 |
|
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Add an Edge computed externally. The label on the Edge is assumed |
|
344 |
* to be correct. |
|
345 |
*/ |
|
346 |
public void addEdge(Edge e) |
|
347 |
{ |
|
348 |
insertEdge(e); |
|
349 |
Coordinate[] coord = e.getCoordinates(); |
|
350 |
// insert the endpoint as a node, to mark that it is on the boundary |
|
351 |
insertPoint(argIndex, coord[0], Location.BOUNDARY); |
|
352 |
insertPoint(argIndex, coord[coord.length - 1], Location.BOUNDARY); |
|
353 |
} |
|
354 |
|
|
355 |
/** |
|
356 |
* Add a point computed externally. The point is assumed to be a |
|
357 |
* Point Geometry part, which has a location of INTERIOR. |
|
358 |
*/ |
|
359 |
public void addPoint(Coordinate pt) |
|
360 |
{ |
|
361 |
insertPoint(argIndex, pt, Location.INTERIOR); |
|
362 |
} |
|
363 |
|
|
364 |
|
|
365 |
/** |
|
366 |
* Compute self-nodes, taking advantage of the Geometry type to |
|
367 |
* minimize the number of intersection tests. (E.g. rings are |
|
368 |
* not tested for self-intersection, since they are assumed to be valid). |
|
369 |
* @param li the LineIntersector to use |
|
370 |
* @param computeRingSelfNodes if <false>, intersection checks are optimized to not test rings for self-intersection |
|
371 |
* @return the SegmentIntersector used, containing information about the intersections found |
|
372 |
*/ |
|
373 |
public SegmentIntersector computeSelfNodes(LineIntersector li, boolean computeRingSelfNodes) |
|
374 |
{ |
|
375 |
SegmentIntersector si = new SegmentIntersector(li, true, false); |
|
376 |
SnapSimpleMCSweepLineIntersector esi = new SnapSimpleMCSweepLineIntersector(); |
|
377 |
// optimized test for Polygons and Rings |
|
378 |
if (! computeRingSelfNodes |
|
379 |
&& (parentGeometry instanceof LinearRing |
|
380 |
|| parentGeometry instanceof Polygon |
|
381 |
|| parentGeometry instanceof MultiPolygon)) { |
|
382 |
esi.computeIntersections(edges, si, false); |
|
383 |
} |
|
384 |
else { |
|
385 |
esi.computeIntersections(edges, si, true); |
|
386 |
} |
|
387 |
addSelfIntersectionNodes(argIndex); |
|
388 |
return si; |
|
389 |
} |
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
public SegmentIntersector computeEdgeIntersections( |
|
394 |
GeometryGraph g, |
|
395 |
LineIntersector li, |
|
396 |
boolean includeProper) |
|
397 |
{ |
|
398 |
SegmentIntersector siSnap = new SegmentIntersector(li, includeProper, true); |
|
399 |
siSnap.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes()); |
|
400 |
|
|
401 |
SnapSimpleMCSweepLineIntersector esiSnap = new SnapSimpleMCSweepLineIntersector(); |
|
402 |
esiSnap.computeIntersections(edges, g.edges, siSnap); |
|
403 |
return siSnap; |
|
404 |
|
|
405 |
// return super.computeEdgeIntersections(g, li, includeProper); |
|
406 |
} |
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
private void addSelfIntersectionNodes(int argIndex) |
|
412 |
{ |
|
413 |
for (Iterator i = edges.iterator(); i.hasNext(); ) { |
|
414 |
Edge e = (Edge) i.next(); |
|
415 |
int eLoc = e.getLabel().getLocation(argIndex); |
|
416 |
for (Iterator eiIt = e.eiList.iterator(); eiIt.hasNext(); ) { |
|
417 |
EdgeIntersection ei = (EdgeIntersection) eiIt.next(); |
|
418 |
addSelfIntersectionNode(argIndex, ei.coord, eLoc); |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
/** |
|
423 |
* Add a node for a self-intersection. |
|
424 |
* If the node is a potential boundary node (e.g. came from an edge which |
|
425 |
* is a boundary) then insert it as a potential boundary node. |
|
426 |
* Otherwise, just add it as a regular node. |
|
427 |
*/ |
|
428 |
private void addSelfIntersectionNode(int argIndex, Coordinate coord, int loc) |
|
429 |
{ |
|
430 |
// if this node is already a boundary node, don't change it |
|
431 |
if (isBoundaryNode(argIndex, coord)) return; |
|
432 |
if (loc == Location.BOUNDARY && useBoundaryDeterminationRule) |
|
433 |
insertBoundaryPoint(argIndex, coord); |
|
434 |
else |
|
435 |
insertPoint(argIndex, coord, loc); |
|
436 |
} |
|
437 |
|
|
438 |
private void insertPoint(int argIndex, Coordinate coord, int onLocation) |
|
439 |
{ |
|
440 |
Node n = nodes.addNode(coord); |
|
441 |
Label lbl = n.getLabel(); |
|
442 |
if (lbl == null) { |
|
443 |
n.label = new Label(argIndex, onLocation); |
|
444 |
} |
|
445 |
else |
|
446 |
lbl.setLocation(argIndex, onLocation); |
|
447 |
} |
|
448 |
|
|
449 |
/** |
|
450 |
* Adds points using the mod-2 rule of SFS. This is used to add the boundary |
|
451 |
* points of dim-1 geometries (Curves/MultiCurves). According to the SFS, |
|
452 |
* an endpoint of a Curve is on the boundary |
|
453 |
* iff if it is in the boundaries of an odd number of Geometries |
|
454 |
*/ |
|
455 |
private void insertBoundaryPoint(int argIndex, Coordinate coord) |
|
456 |
{ |
|
457 |
Node n = nodes.addNode(coord); |
|
458 |
Label lbl = n.getLabel(); |
|
459 |
// the new point to insert is on a boundary |
|
460 |
int boundaryCount = 1; |
|
461 |
// determine the current location for the point (if any) |
|
462 |
int loc = Location.NONE; |
|
463 |
if (lbl != null) loc = lbl.getLocation(argIndex, Position.ON); |
|
464 |
if (loc == Location.BOUNDARY) boundaryCount++; |
|
465 |
|
|
466 |
// determine the boundary status of the point according to the Boundary Determination Rule |
|
467 |
int newLoc = determineBoundary(boundaryCount); |
|
468 |
lbl.setLocation(argIndex, newLoc); |
|
469 |
} |
|
470 |
|
|
471 |
|
|
472 |
public void computeSplitEdges(List edgelist) |
|
473 |
{ |
|
474 |
for (Iterator i = edges.iterator(); i.hasNext(); ) { |
|
475 |
SnappingEdge e = (SnappingEdge) i.next(); |
|
476 |
e.getEdgeIntersectionList().addSplitEdges(edgelist); |
|
477 |
} |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Borra las intersecciones registradas en los nodos |
|
482 |
* (util de cara a reutilizar un GeometryGraph en multiples intersecciones) |
|
483 |
* */ |
|
484 |
public void clearIntersections(){ |
|
485 |
for (Iterator i = edges.iterator(); i.hasNext(); ) { |
|
486 |
SnappingEdge e = (SnappingEdge) i.next(); |
|
487 |
e.clearIntersections(); |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
0 | 491 |
tags/gvsig_redes-1_0_0-1233/prototypes/VectorialAvanzado/extensions/extGraph/src/com/vividsolutions/jts/geomgraph/SnappingPlanarGraph.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 11-sep-2006 by azabala |
|
3 |
* |
|
4 |
*/ |
|
5 |
package com.vividsolutions.jts.geomgraph; |
|
6 |
|
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.Collection; |
|
9 |
import java.util.Iterator; |
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
|
13 |
import com.vividsolutions.jts.geom.Coordinate; |
|
14 |
import com.vividsolutions.jts.geom.Location; |
|
15 |
import com.vividsolutions.jts.geomgraph.DirectedEdgeStar; |
|
16 |
import com.vividsolutions.jts.geomgraph.Edge; |
|
17 |
import com.vividsolutions.jts.geomgraph.EdgeEnd; |
|
18 |
import com.vividsolutions.jts.geomgraph.EdgeEndStar; |
|
19 |
import com.vividsolutions.jts.geomgraph.Label; |
|
20 |
import com.vividsolutions.jts.geomgraph.Node; |
|
21 |
import com.vividsolutions.jts.geomgraph.NodeFactory; |
|
22 |
import com.vividsolutions.jts.geomgraph.PlanarGraph; |
|
23 |
import com.vividsolutions.jts.geomgraph.Quadrant; |
|
24 |
|
|
25 |
/** |
|
26 |
* @author alzabord |
|
27 |
* |
|
28 |
* TODO To change the template for this generated type comment go to Window - |
|
29 |
* Preferences - Java - Code Style - Code Templates |
|
30 |
*/ |
|
31 |
public class SnappingPlanarGraph extends PlanarGraph { |
|
32 |
|
|
33 |
public static final CGAlgorithms cga = new CGAlgorithms(); |
|
34 |
|
|
35 |
protected List edges = new ArrayList(); |
|
36 |
|
|
37 |
protected SnappingNodeMap nodes; |
|
38 |
|
|
39 |
protected List edgeEndList = new ArrayList(); |
|
40 |
|
|
41 |
|
|
42 |
/** |
|
43 |
* For nodes in the Collection, link the DirectedEdges at the node that are |
|
44 |
* in the result. This allows clients to link only a subset of nodes in the |
|
45 |
* graph, for efficiency (because they know that only a subset is of |
|
46 |
* interest). |
|
47 |
*/ |
|
48 |
public static void linkResultDirectedEdges(Collection nodes) { |
|
49 |
for (Iterator nodeit = nodes.iterator(); nodeit.hasNext();) { |
|
50 |
Node node = (Node) nodeit.next(); |
|
51 |
DirectedEdgeStar edgeStar = (DirectedEdgeStar) node.getEdges(); |
|
52 |
edgeStar.linkResultDirectedEdges(); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public SnappingPlanarGraph(NodeFactory nodeFact, double tolerance) { |
|
57 |
nodes = new SnappingNodeMap(nodeFact, tolerance); |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
public SnappingPlanarGraph(double tolerance) { |
|
62 |
nodes = new SnappingNodeMap(new NodeFactory(), tolerance); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
public Iterator getEdgeIterator() { |
|
67 |
return edges.iterator(); |
|
68 |
} |
|
69 |
|
|
70 |
public Collection getEdgeEnds() { |
|
71 |
return edgeEndList; |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
public boolean isBoundaryNode(int geomIndex, Coordinate coord) { |
|
76 |
Node node = nodes.find(coord); |
|
77 |
if (node == null) |
|
78 |
return false; |
|
79 |
Label label = node.getLabel(); |
|
80 |
if (label != null && label.getLocation(geomIndex) == Location.BOUNDARY) |
|
81 |
return true; |
|
82 |
return false; |
|
83 |
} |
|
84 |
|
|
85 |
protected void insertEdge(Edge e) { |
|
86 |
edges.add(e); |
|
87 |
} |
Also available in: Unified diff