Revision 11410

View differences:

tags/PilotoRedes_Build_2/extensions/extGraph_predes/plantilla.htm
1
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
2
<html>
3
<head>
4
<title>Documento sin t&iacute;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'>&nbsp;
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">&nbsp;</td>
60
    <td class="distancia">Distancia acumulada: 447.44 metros</td>
61
  </tr><tr>
62
    <td width="40">&nbsp;
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">&nbsp;</td>
69
    <td class="distancia">Distancia acumulada: 2,768.02</td>
70
  </tr><tr>
71
    <td width="40">&nbsp;
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">&nbsp;</td>
80
    <td class="distancia">Distancia acumulada: 3,124.01</td>
81
  </tr><tr>
82
    <td width="40">&nbsp;
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">&nbsp;</td>
91
    <td class="distancia">Longitud: 9,020.31</td>
92
  </tr><tr>
93
    <td width="40">&nbsp;
94
    <td><a href="images/24">Ver sobre el mapa</a></tr></table>
95
 </body>
96
</html>
0 97

  
tags/PilotoRedes_Build_2/extensions/extGraph_predes/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/PilotoRedes_Build_2/extensions/extGraph_predes/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/PilotoRedes_Build_2/extensions/extGraph_predes/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/PilotoRedes_Build_2/extensions/extGraph_predes/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
	}
88
	
89

  
90
	
91
	public void add(EdgeEnd e) {
92
		nodes.add(e);
93
		edgeEndList.add(e);
94
	}
95
	
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
	
122
	/**
123
	 * Add a set of edges to the graph. 
124
	 * For each edge two DirectedEdges will be
125
	 * created. DirectedEdges are NOT linked by this method.
126
	 */
127
	public void addEdges(List edgesToAdd) {
128
		// create all the nodes for the edges
129
		for (Iterator it = edgesToAdd.iterator(); it.hasNext();) {
130
			Edge e = (Edge) it.next();
131
			edges.add(e);
132
			SnapDirectedEdge de1 = new SnapDirectedEdge(e, true);
133
			SnapDirectedEdge de2 = new SnapDirectedEdge(e, false);
134
			de1.setSym(de2);
135
			de2.setSym(de1);
136
//IMPORTAR VER QUE PASA AQU?: Para cada nuevo Edge, construye un EdgeEnd que puede dar a lugar a un nodo y que origina un Edge
137
			add(de1);
138
			add(de2);
139
		}
140
	}
141

  
142
	/**
143
	 * Link the DirectedEdges at the nodes of the graph. This allows clients to
144
	 * link only a subset of nodes in the graph, for efficiency (because they
145
	 * know that only a subset is of interest).
146
	 */
147
	public void linkResultDirectedEdges() {
148
		for (Iterator nodeit = nodes.iterator(); nodeit.hasNext();) {
149
			Node node = (Node) nodeit.next();
150
			((DirectedEdgeStar) node.getEdges()).linkResultDirectedEdges();
151
		}
152
	}
153

  
154
	/**
155
	 * Link the DirectedEdges at the nodes of the graph. This allows clients to
156
	 * link only a subset of nodes in the graph, for efficiency (because they
157
	 * know that only a subset is of interest).
158
	 */
159
	public void linkAllDirectedEdges() {
160
		for (Iterator nodeit = nodes.iterator(); nodeit.hasNext();) {
161
			Node node = (Node) nodeit.next();
162
			((DirectedEdgeStar) node.getEdges()).linkAllDirectedEdges();
163
		}
164
	}
165

  
166
	/**
167
	 * Returns the EdgeEnd which has edge e as its base edge (MD 18 Feb 2002 -
168
	 * this should return a pair of edges)
169
	 * 
170
	 * @return the edge, if found <code>null</code> if the edge was not found
171
	 */
172
	public EdgeEnd findEdgeEnd(Edge e) {
173
		for (Iterator i = getEdgeEnds().iterator(); i.hasNext();) {
174
			EdgeEnd ee = (EdgeEnd) i.next();
175
			if (ee.getEdge() == e)
176
				return ee;
177
		}
178
		return null;
179
	}
180

  
181
	/**
182
	 * Returns the edge whose first two coordinates are p0 and p1
183
	 * 
184
	 * @return the edge, if found <code>null</code> if the edge was not found
185
	 */
186
	public Edge findEdge(Coordinate p0, Coordinate p1) {
187
		for (int i = 0; i < edges.size(); i++) {
188
			Edge e = (Edge) edges.get(i);
189
			Coordinate[] eCoord = e.getCoordinates();
190
			if (p0.equals(eCoord[0]) && p1.equals(eCoord[1]))
191
				return e;
192
		}
193
		return null;
194
	}
195

  
196
	/**
197
	 * Returns the edge which starts at p0 and whose first segment is parallel
198
	 * to p1
199
	 * 
200
	 * @return the edge, if found <code>null</code> if the edge was not found
201
	 */
202
	public Edge findEdgeInSameDirection(Coordinate p0, Coordinate p1) {
203
		for (int i = 0; i < edges.size(); i++) {
204
			Edge e = (Edge) edges.get(i);
205

  
206
			Coordinate[] eCoord = e.getCoordinates();
207
			if (matchInSameDirection(p0, p1, eCoord[0], eCoord[1]))
208
				return e;
209

  
210
			if (matchInSameDirection(p0, p1, eCoord[eCoord.length - 1],
211
					eCoord[eCoord.length - 2]))
212
				return e;
213
		}
214
		return null;
215
	}
216

  
217
	/**
218
	 * The coordinate pairs match if they define line segments lying in the same
219
	 * direction. E.g. the segments are parallel and in the same quadrant (as
220
	 * opposed to parallel and opposite!).
221
	 */
222
	private boolean matchInSameDirection(Coordinate p0, Coordinate p1,
223
			Coordinate ep0, Coordinate ep1) {
224
		if (!p0.equals(ep0))
225
			return false;
226

  
227
		if (CGAlgorithms.computeOrientation(p0, p1, ep1) == CGAlgorithms.COLLINEAR
228
				&& Quadrant.quadrant(p0, p1) == Quadrant.quadrant(ep0, ep1))
229
			return true;
230
		return false;
231
	}
232
	
233
	public void dump(){
234
		System.out.println("EDGES");
235
		Iterator it = this.getEdgeIterator();
236
		while(it.hasNext()){
237
			Edge e = (Edge) it.next();
238
			e.print(System.out);
239
			System.out.println("");
240
		}
241
		System.out.println("NODES");
242
		it = this.getNodeIterator();
243
		while(it.hasNext()){
244
			Node node = (Node) it.next();
245
			System.out.println(node.getCoordinate());
246
			System.out.println(node.getLabel());
247
			List edges = node.getEdges().getEdges();
248
			for(int z = 0; z < edges.size(); z++){
249
				EdgeEnd ee = (EdgeEnd) edges.get(z);
250
				Label eeL = ee.getLabel();
251
				System.out.println(ee.toString() + "," + eeL.toString());
252
			}
253
		}
254
//		nodes.dump();
255
	}
256

  
257
}
0 258

  
tags/PilotoRedes_Build_2/extensions/extGraph_predes/src/com/vividsolutions/jts/geomgraph/SnapEdgeList.java
1
/*
2
 * Created on 04-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
*
55
*/
56
package com.vividsolutions.jts.geomgraph;
57

  
58
import java.awt.geom.Rectangle2D;
59
import java.util.ArrayList;
60
import java.util.Collection;
61
import java.util.Iterator;
62
import java.util.List;
63

  
64
import com.iver.cit.gvsig.fmap.spatialindex.RTreeJsi;
65
import com.vividsolutions.jts.geom.Envelope;
66
import com.vividsolutions.jts.geomgraph.Edge;
67
import com.vividsolutions.jts.geomgraph.EdgeList;
68
import com.vividsolutions.jts.index.SpatialIndex;
69
import com.vividsolutions.jts.index.quadtree.Quadtree;
70
/**
71
 * Overwrites jts' EdgeList to allow spatial queries
72
 * consideering snap.
73
 * 
74
 * (for example, (0 0, 5 0) and (0.01 0.01, 5.01 0.02)
75
 * arent equivalent in findEqualEdge, even thought with a
76
 * snap distance of 0.1
77
 * 
78
 * 
79
 * 
80
 * */
81
public class SnapEdgeList extends EdgeList {
82
	private List edges = new ArrayList();
83
	 
84
//	  private SpatialIndex index = new Quadtree();
85
	
86
	//El quadtree no funciona bien para indexar dimensiones
87
	//lineales o lineas.
88
	
89
	  private RTreeJsi spatialIndex = new RTreeJsi();
90
	  private double snapTolerance;
91
	  
92
	  
93
	  
94
	  public SnapEdgeList(double snapTolerance) {
95
		  this.snapTolerance = snapTolerance;
96
	  }
97

  
98
	  /**
99
	   * Insert an edge unless it is already in the list
100
	   */
101
	  public void add(Edge e)
102
	  {
103
//        int position = edges.size();		  
104
	    edges.add(e);
105
	    //TODO me peta el indice espacial
106
//	    Envelope oldEnvelope = e.getEnvelope();
107
//		Rectangle2D newEnvelope = getEnvelopeForSnap(oldEnvelope);
108
//		spatialIndex.insert(newEnvelope, position);
109
	  }
110

  
111
	  private Rectangle2D getEnvelopeForSnap(Envelope oldEnvelope){
112
			double xmin = oldEnvelope.getMinX() - snapTolerance;
113
		  	double ymin = oldEnvelope.getMinY() - snapTolerance;
114
		  	double width = oldEnvelope.getWidth() + snapTolerance;
115
		  	double height = oldEnvelope.getHeight() + snapTolerance;
116
		  	
117
		  	return new Rectangle2D.Double(xmin, ymin, width, height);
118
	  }
119

  
120

  
121
//	 <FIX> fast lookup for edges
122
	  /**
123
	   * If there is an edge equal to e already in the list, return it.
124
	   * Otherwise return null.
125
	   * @return  equal edge, if there is one already in the list
126
	   *          null otherwise
127
	   */
128
	  public Edge findEqualEdge(Edge e)
129
	  {
130
		  //TODO NO ENCUENTRO UN INDICE ESPACIAL EN CONDICIONES
131
//	    Collection testEdges = spatialIndex.
132
//	     query(getEnvelopeForSnap(e.getEnvelope()));
133
		  //PETA CON QUADTREE Y CON RTREE DE JSI
134

  
135
		Collection testEdges = edges;  
136
		  
137
	    for (Iterator i = testEdges.iterator(); i.hasNext(); ) {
138
	    	//TODO me peta el indice espacial
139
//	      int index = ((Integer)i.next()).intValue();
140
	      Edge testEdge = (Edge) i.next();	
141
	    	
142
//	      Edge testEdge = (Edge) edges.get(index);
143
	      if (testEdge.equals(e) ) return testEdge;
144
	    }
145
	    return null;
146
	  }
147
	  
148
	  public void addAll(Collection edgeColl)
149
	  {
150
	    for (Iterator i = edgeColl.iterator(); i.hasNext(); ) {
151
	      add((Edge) i.next());
152
	    }
153
	  }
154
	  
155
	  public Iterator iterator() { return edges.iterator(); }
156

  
157
	  public Edge get(int i) { return (Edge) edges.get(i); }
158

  
159
	  /**
160
	   * If the edge e is already in the list, return its index.
161
	   * @return  index, if e is already in the list
162
	   *          -1 otherwise
163
	   */
164
	  public int findEdgeIndex(Edge e)
165
	  {
166
	    for (int i = 0; i < edges.size(); i++) {
167
	      if ( ((Edge) edges.get(i)).equals(e) ) return i;
168
	    }
169
	    return -1;
170
	  }
171

  
172
	  
173
	  public List getEdges() { return edges; }
174

  
175
}
176

  
0 177

  
tags/PilotoRedes_Build_2/extensions/extGraph_predes/src/com/vividsolutions/jts/geomgraph/SnappingNodeMap.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.Collections;
10
import java.util.Comparator;
11
import java.util.HashMap;
12
import java.util.Iterator;
13
import java.util.List;
14

  
15
import com.vividsolutions.jts.algorithms.SnapSimplePointInAreaLocator;
16
import com.vividsolutions.jts.geom.Coordinate;
17
import com.vividsolutions.jts.geom.Envelope;
18
import com.vividsolutions.jts.geom.Location;
19
import com.vividsolutions.jts.geom.TopologyException;
20
import com.vividsolutions.jts.geomgraph.DirectedEdge;
21
import com.vividsolutions.jts.geomgraph.DirectedEdgeStar;
22
import com.vividsolutions.jts.geomgraph.Edge;
23
import com.vividsolutions.jts.geomgraph.EdgeEnd;
24
import com.vividsolutions.jts.geomgraph.EdgeEndStar;
25
import com.vividsolutions.jts.geomgraph.GeometryGraph;
26
import com.vividsolutions.jts.geomgraph.Label;
27
import com.vividsolutions.jts.geomgraph.Node;
28
import com.vividsolutions.jts.geomgraph.NodeFactory;
29
import com.vividsolutions.jts.geomgraph.NodeMap;
30
import com.vividsolutions.jts.geomgraph.Position;
31
import com.vividsolutions.jts.util.Assert;
32

  
33
/**
34
 * Repository of nodes of a PlanarGraph that applies a snap tolerance.
35
 * 
36
 * If we ask for a node, and it founds a node in the tolerance distance it
37
 * returns the found node.
38
 * 
39
 * 
40
 * 
41
 * @author alzabord
42
 */
43
public class SnappingNodeMap extends NodeMap {
44

  
45
	
46

  
47
	// Esto  va a ir muy lento
48
	// buscar otros mecanismos (indice espacial, o hashmap)
49
	protected HashMap nodeMap;
50

  
51
	private class SnapDirectedEdgeStar extends DirectedEdgeStar {
52

  
53
		/**
54
		 * The location of the point for this star in Geometry i Areas
55
		 */
56
		private int[] ptInAreaLocation = { Location.NONE, Location.NONE };
57

  
58
		private Label label;
59

  
60
		List resultAreaEdgeList = null;
61

  
62
		List getResultAreaEdges() {
63
			if (resultAreaEdgeList != null)
64
				return resultAreaEdgeList;
65
			resultAreaEdgeList = new ArrayList();
66
			for (Iterator it = iterator(); it.hasNext();) {
67
				DirectedEdge de = (DirectedEdge) it.next();
68
				if (de.isInResult() || de.getSym().isInResult())
69
					resultAreaEdgeList.add(de);
70
			}
71
			return resultAreaEdgeList;
72
		}
73

  
74
		private final int SCANNING_FOR_INCOMING = 1;
75

  
76
		private final int LINKING_TO_OUTGOING = 2;
77

  
78
		private SnapDirectedEdgeStar() {
79
			super();
80

  
81
			edgeList = new ArrayList();
82

  
83
		}
84

  
85
		/**
86
		 * Traverse the star of DirectedEdges, linking the included edges
87
		 * together. To link two dirEdges, the <next> pointer for an incoming
88
		 * dirEdge is set to the next outgoing edge.
89
		 * <p>
90
		 * DirEdges are only linked if:
91
		 * <ul>
92
		 * <li>they belong to an area (i.e. they have sides)
93
		 * <li>they are marked as being in the result
94
		 * </ul>
95
		 * <p>
96
		 * Edges are linked in CCW order (the order they are stored). This means
97
		 * that rings have their face on the Right (in other words, the
98
		 * topological location of the face is given by the RHS label of the
99
		 * DirectedEdge)
100
		 * <p>
101
		 * PRECONDITION: No pair of dirEdges are both marked as being in the
102
		 * result
103
		 */
104
		public void linkResultDirectedEdges() {
105
			// make sure edges are copied to resultAreaEdges list
106
			List resultEdges = getResultAreaEdges();
107
			// find first area edge (if any) to start linking at
108
			DirectedEdge firstOut = null;
109
			DirectedEdge incoming = null;
110
			int state = SCANNING_FOR_INCOMING;
111
			// link edges in CCW order
112
			for (int i = 0; i < resultAreaEdgeList.size(); i++) {
113
				DirectedEdge nextOut = (DirectedEdge) resultEdges.get(i);
114
				DirectedEdge nextIn = nextOut.getSym();
115

  
116
				// skip de's that we're not interested in
117
				if (!nextOut.getLabel().isArea())
118
					continue;
119

  
120
				// record first outgoing edge, in order to link the last
121
				// incoming edge
122
				if (firstOut == null && nextOut.isInResult())
123
					firstOut = nextOut;
124
				// assert: sym.isInResult() == false, since pairs of dirEdges
125
				// should have been removed already
126

  
127
				switch (state) {
128
				case SCANNING_FOR_INCOMING:
129
					if (!nextIn.isInResult())
130
						continue;
131
					incoming = nextIn;
132
					state = LINKING_TO_OUTGOING;
133
					break;
134
				case LINKING_TO_OUTGOING:
135
					if (!nextOut.isInResult())
136
						continue;
137
					incoming.setNext(nextOut);
138
					state = SCANNING_FOR_INCOMING;
139
					break;
140
				}
141
			}// for
142
			if (state == LINKING_TO_OUTGOING) {
143
				// Debug.print(firstOut == null, this);
144
				if (firstOut == null)
145
					throw new TopologyException("no outgoing dirEdge found",
146
							getCoordinate());
147
				// Assert.isTrue(firstOut != null, "no outgoing dirEdge found
148
				// (at " + getCoordinate() );
149
				Assert.isTrue(firstOut.isInResult(),
150
						"unable to link last incoming dirEdge");
151
				incoming.setNext(firstOut);
152
			}
153
		}
154

  
155
		/**
156
		 * Insert an EdgeEnd into the map, and clear the edgeList cache, since
157
		 * the list of edges has now changed
158
		 */
159
		protected void insertEdgeEnd(EdgeEnd e, Object obj) {
160
			edgeMap.put(e, obj);
161
			if (edgeList == null)
162
				edgeList = new ArrayList();
163
			edgeList.add(e);
164

  
165
			// Necesitamos que la "estrella" de Ejes asociada a un Nodo conserve
166
			// siempre un orden antihorario. Por eso, cada vez que se a?ada un
167
			// nuevo
168
			// eje solo se inserta en el Map (que mantiene el orden)
169
			// y la cache se pone a null
170

  
171
			// edgeList = null;
172
		}
173

  
174
		public Iterator iterator() {
175
			return getEdges().iterator();
176
		}
177

  
178
		public List getEdges() {
179
			Collections.sort(edgeList, new Comparator() {
180
				public int compare(Object arg0, Object arg1) {
181
					EdgeEnd e0 = (EdgeEnd) arg0;
182
					EdgeEnd e1 = (EdgeEnd) arg1;
183
					return e0.compareTo(e1);
184
				}
185
			});
186
			// if (edgeList == null) {
187
			// edgeList = new ArrayList(edgeMap.values());
188
			// }
189
			return edgeList;
190
		}
191

  
192
		public Label getLabel() {
193
			return label;
194
		}
195

  
196
		void computeEdgeEndLabels() {
197
			// Compute edge label for each EdgeEnd
198
			for (Iterator it = iterator(); it.hasNext();) {
199
				EdgeEnd ee = (EdgeEnd) it.next();
200
				ee.computeLabel();
201
			}
202
		}
203

  
204
		void propagateSideLabels(int geomIndex) {
205
			// Since edges are stored in CCW order around the node,
206
			// As we move around the ring we move from the right to the left
207
			// side of the edge
208
			int startLoc = Location.NONE;
209
			// initialize loc to location of last L side (if any)
210
			// System.out.println("finding start location");
211
			for (Iterator it = iterator(); it.hasNext();) {
212
				EdgeEnd e = (EdgeEnd) it.next();
213
				Label label = e.getLabel();
214
				if (label.isArea(geomIndex)
215
						&& label.getLocation(geomIndex, Position.LEFT) != Location.NONE)
216
					startLoc = label.getLocation(geomIndex, Position.LEFT);
217
			}
218
			// no labelled sides found, so no labels to propagate
219
			if (startLoc == Location.NONE)
220
				return;
221

  
222
			int currLoc = startLoc;
223
			for (Iterator it = iterator(); it.hasNext();) {
224
				EdgeEnd e = (EdgeEnd) it.next();
225
				Label label = e.getLabel();
226
				// set null ON values to be in current location
227
				if (label.getLocation(geomIndex, Position.ON) == Location.NONE)
228
					label.setLocation(geomIndex, Position.ON, currLoc);
229
				// set side labels (if any)
230
				// if (label.isArea()) { //ORIGINAL
231
				if (label.isArea(geomIndex)) {
232
					int leftLoc = label.getLocation(geomIndex, Position.LEFT);
233
					int rightLoc = label.getLocation(geomIndex, Position.RIGHT);
234
					// if there is a right location, that is the next location
235
					// to propagate
236
					if (rightLoc != Location.NONE) {
237
						// Debug.print(rightLoc != currLoc, this);
238
						if (rightLoc != currLoc)
239
							throw new TopologyException(
240
									"side location conflict", e.getCoordinate());
241
						if (leftLoc == Location.NONE) {
242
							Assert
243
									.shouldNeverReachHere("found single null side (at "
244
											+ e.getCoordinate() + ")");
245
						}
246
						currLoc = leftLoc;
247
					} else {
248
						/**
249
						 * RHS is null - LHS must be null too. This must be an
250
						 * edge from the other geometry, which has no location
251
						 * labelling for this geometry. This edge must lie
252
						 * wholly inside or outside the other geometry (which is
253
						 * determined by the current location). Assign both
254
						 * sides to be the current location.
255
						 */
256
						Assert.isTrue(label.getLocation(geomIndex,
257
								Position.LEFT) == Location.NONE,
258
								"found single null side");
259
						label.setLocation(geomIndex, Position.RIGHT, currLoc);
260
						label.setLocation(geomIndex, Position.LEFT, currLoc);
261
					}
262
				}
263
			}
264
		}
265

  
266
		int getLocation(int geomIndex, Coordinate p, GeometryGraph[] geom) {
267
			// compute location only on demand
268
			if (ptInAreaLocation[geomIndex] == Location.NONE) {
269
				ptInAreaLocation[geomIndex] = SnapSimplePointInAreaLocator
270
						.locate(p, geom[geomIndex].getGeometry(), snapTolerance);
271
			}
272
			return ptInAreaLocation[geomIndex];
273
		}
274

  
275
		public void mergeSymLabels() {
276
			for (Iterator it = iterator(); it.hasNext();) {
277
				DirectedEdge de = (DirectedEdge) it.next();
278
				Label label = de.getLabel();
279
				Label symLabel = de.getSym().getLabel();
280
				label.merge(symLabel);
281
			}
282
		}
283

  
284
		/**
285
		 * Update incomplete dirEdge labels from the labelling for the node
286
		 */
287
		public void updateLabelling(Label nodeLabel) {
288
			for (Iterator it = iterator(); it.hasNext();) {
289
				DirectedEdge de = (DirectedEdge) it.next();
290
				Label label = de.getLabel();
291
				label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));
292
				label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));
293
			}
294
		}
295

  
296
		public void computeLabelling(GeometryGraph[] geom) {
297
			computeEdgeEndLabels();
298
			propagateSideLabels(0);
299
			propagateSideLabels(1);
300
			boolean[] hasDimensionalCollapseEdge = { false, false };
301
			for (Iterator it = iterator(); it.hasNext();) {
302
				EdgeEnd e = (EdgeEnd) it.next();
303
				Label label = e.getLabel();
304
				for (int geomi = 0; geomi < 2; geomi++) {
305
					if (label.isLine(geomi)
306
							&& label.getLocation(geomi) == Location.BOUNDARY)
307
						hasDimensionalCollapseEdge[geomi] = true;
308
				}
309
			}
310
			for (Iterator it = iterator(); it.hasNext();) {
311
				EdgeEnd e = (EdgeEnd) it.next();
312
				Label label = e.getLabel();
313
				for (int geomi = 0; geomi < 2; geomi++) {
314
					if (label.isAnyNull(geomi)) {
315
						int loc = Location.NONE;
316
						if (hasDimensionalCollapseEdge[geomi]) {
317
							loc = Location.EXTERIOR;
318
						} else {
319
							Coordinate p = e.getCoordinate();
320
							loc = getLocation(geomi, p, geom);
321
						}
322
						label.setAllLocationsIfNull(geomi, loc);
323
					}// if
324
				}// for
325
			}// for
326

  
327
			// determine the overall labelling for this DirectedEdgeStar
328
			// (i.e. for the node it is based at)
329
			label = new Label(Location.NONE);
330
			for (Iterator it = iterator(); it.hasNext();) {
331
				EdgeEnd ee = (EdgeEnd) it.next();
332
				Edge e = ee.getEdge();
333
				Label eLabel = e.getLabel();
334
				for (int i = 0; i < 2; i++) {
335
					int eLoc = eLabel.getLocation(i);
336
					if (eLoc == Location.INTERIOR || eLoc == Location.BOUNDARY)
337
						label.setLocation(i, Location.INTERIOR);
338
				}
339
			}
340
		}
341
	}
342

  
343
	class SnapNode extends Node {
344

  
345
		public SnapNode(Coordinate arg0, EdgeEndStar arg1) {
346
			super(arg0, arg1);
347
		}
348

  
349
		public boolean equals(Object obj) {
350
			SnapNode other = (SnapNode) obj;
351
			return other.coord.distance(this.coord) <= snapTolerance;
352
		}
353

  
354
		public int hashCode() {
355
			return 1; // esto no es eficiente
356
		}
357
	}
358

  
359
	private double snapTolerance;
360

  
361
	public SnappingNodeMap(NodeFactory nodeFactory, double snapTolerance) {
362
		super(nodeFactory);
363
		this.snapTolerance = snapTolerance;
364
		// spatialIndex = new Quadtree();
365
		nodeMap = new HashMap();
366
	}
367

  
368
	class MinDistCoordComparator implements Comparator {
369
		Coordinate coord;
370

  
371
		MinDistCoordComparator(Coordinate coord) {
372
			this.coord = coord;
373
		}
374

  
375
		public int compare(Object arg0, Object arg1) {
376
			Coordinate c1 = ((Node) arg0).getCoordinate();
377
			Coordinate c2 = ((Node) arg1).getCoordinate();
378

  
379
			double d1 = c1.distance(coord);
380
			double d2 = c2.distance(coord);
381

  
382
			if (d1 < d2)
383
				return 1;
384
			if (d1 > d2)
385
				return -1;
386
			else
387
				return 0;
388
		}
389
	}
390

  
391
	private Envelope getQueryRect(Coordinate coord) {
392
		double xmin = coord.x - snapTolerance;
393
		double ymin = coord.y - snapTolerance;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff