Revision 8487

View differences:

trunk/extensions/extGraph_predes/src-test/com/iver/cit/gvsig/graphtests/TestLoader.java
29 29
import com.iver.cit.gvsig.graph.core.IGraph;
30 30
import com.iver.cit.gvsig.graph.core.JungGraph;
31 31
import com.iver.cit.gvsig.graph.core.Network;
32
import com.iver.cit.gvsig.graph.core.NetworkLoader;
33
import com.iver.cit.gvsig.graph.core.NetworkRedLoader;
32
import com.iver.cit.gvsig.graph.core.loaders.NetworkLoader;
33
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
34 34
import com.iver.cit.gvsig.graph.solvers.Route;
35 35
import com.iver.cit.gvsig.graph.solvers.ShortestPathSolver;
36 36

  
trunk/extensions/extGraph_predes/src-test/com/iver/cit/gvsig/graphtests/TestWriter.java
6 6
import java.sql.ResultSet;
7 7
import java.sql.SQLException;
8 8
import java.sql.Statement;
9
import java.sql.Types;
9 10

  
10 11
import junit.framework.TestCase;
11 12

  
12 13
import org.cresques.cts.IProjection;
13 14

  
15
import com.hardcode.gdbms.driver.mysql.MySQLDriver;
14 16
import com.hardcode.gdbms.driver.postgresql.PostgreSQLDriver;
15 17
import com.iver.cit.gvsig.fmap.DriverException;
16 18
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
19
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
17 20
import com.iver.cit.gvsig.fmap.edition.EditionException;
21
import com.iver.cit.gvsig.fmap.edition.IWriter;
18 22
import com.iver.cit.gvsig.fmap.edition.writers.JdbcWriter;
19 23
import com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter;
20 24
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
21 25
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
22
import com.iver.cit.gvsig.graph.core.NetworkWriter;
26
import com.iver.cit.gvsig.graph.core.writers.NetworkFileRedWriter;
23 27

  
24 28
public class TestWriter extends TestCase {
25
	NetworkWriter netBuilder = new NetworkWriter();
29
	NetworkFileRedWriter netBuilder = new NetworkFileRedWriter();
26 30
	FLyrVect lyr;
27 31
	File redFile;
28 32
	/*
......
87 91
		DbfWriter edgeWriter = new DbfWriter();
88 92
		edgeWriter.setFile(edgeFile);
89 93
		
90
		// Para postgres:
94
		// Para mysql:
91 95
		// primero creamos 2 tablas y luego usamos JdbcWriter para a?adir los campos
92 96
		// y rellenar las tablas
93
		/* JdbcWriter pgEdgeWriter = new JdbcWriter();
97
		JdbcWriter pgEdgeWriter = new JdbcWriter();
94 98
		pgEdgeWriter.setCreateTable(true);
95 99
		pgEdgeWriter.setWriteAll(true);
96 100
		
......
98 102
		pgNodeWriter.setCreateTable(true);
99 103
		pgNodeWriter.setWriteAll(true);
100 104
		
101
		PostgreSQLDriver pgDriver = new PostgreSQLDriver();
105
		MySQLDriver myDriver = new MySQLDriver();
102 106
		
103
		Connection conn = pgDriver.getConnection("localhost", 5432, "latin1", "postgres", "aquilina");
107
		Connection conn = myDriver.getConnection("localhost", 3306, "test", "root", "aquilina");
104 108
		Statement stCreate = conn.createStatement();
105 109
		try {
106 110
			stCreate.execute("DROP TABLE nodes;");
......
113 117
			// Si no existe la tabla, no hay que borrarla.
114 118
		}
115 119

  
116
		stCreate.execute("CREATE TABLE nodes (id int4, x float8, y float8);");
117
		stCreate.execute("CREATE TABLE edges ();");
120
		stCreate.execute("CREATE TABLE nodes (NODEID int4, X float8, Y float8);");
121
		stCreate.execute("ALTER TABLE nodes MODIFY COLUMN NODEID INTEGER, ADD PRIMARY KEY(NODEID);");
122
		stCreate.execute("CREATE TABLE edges (ArcID int4, Direction int2, NodeOrigin int4, " +
123
				"NodeEnd int4, Type int4, Dist float8, Cost float8);");
124

  
125
		conn.setAutoCommit(false);
118 126
		conn.commit();
119
		conn.setAutoCommit(false);
120

  
127
//		conn.setAutoCommit(true);
121 128
		
122 129
		Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
123 130
				ResultSet.CONCUR_UPDATABLE);
124
		ResultSet res = st.executeQuery("SELECT nodes.oid, nodes.* FROM nodes;");
131
		ResultSet res = st.executeQuery("SELECT * FROM nodes;");
125 132
		if (res.getConcurrency() != ResultSet.CONCUR_UPDATABLE) {
126 133
			System.err.println("Error: No se puede editar la tabla nodes");
127 134
			return;
128 135
		}
129
		// res.moveToInsertRow();
130

  
131
		ResultSet resEdges = st.executeQuery("SELECT edges.oid, edges.* FROM edges;");
132
		pgEdgeWriter.initialize(conn, res);
133
		pgNodeWriter.initialize(conn, resEdges);
136
		ResultSet resEdges = st.executeQuery("SELECT * FROM edges;");
137
		JdbcWriter jdbcEdgeWriter = (JdbcWriter) myDriver.getWriter();
138
		JdbcWriter jdbcNodeWriter = (JdbcWriter) myDriver.getWriter();
139
		jdbcNodeWriter.initialize(conn, res);
140
		jdbcEdgeWriter.initialize(conn, resEdges);
134 141
		
135
		netBuilder.setEdgeWriter(pgEdgeWriter);
136
		netBuilder.setNodeWriter(pgNodeWriter); */
137 142

  
143
		netBuilder.setEdgeWriter(jdbcEdgeWriter);
144
		netBuilder.setNodeWriter(jdbcNodeWriter);
138 145

  
139
		netBuilder.setEdgeWriter(edgeWriter);
140
		netBuilder.setNodeWriter(nodeWriter);
141 146
		
147
//		netBuilder.setEdgeWriter(edgeWriter);
148
//		netBuilder.setNodeWriter(nodeWriter);
142 149
		
143 150
		
151
		
144 152
	}
145 153

  
146 154
}
trunk/extensions/extGraph_predes/images/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: #0000FF;} --> 
8
</style>
9

  
10
</head>
11

  
12
<body>
13
<h1>Informe de Ruta:SOMONTES AL PALACIO DE LA REAL QUINTA-MONTE CARMELO</h1>
14
<br>Salida desde: <b>SOMONTES AL PALACIO DE LA REAL QUINTA</b><br>
15
Llegada a:<b> MONTE CARMELO</b><br>Longitud total del trayecto: <b>9,020.31</b>
16
<hr width ="70%">
17
<table>
18
<tr>
19
<td><img src="images/drapeau_depart.gif"></td><td class='normal'>1. Salir de:<b> SOMONTES AL PALACIO DE LA REAL QUINTA</b></td></tr><tr><td class='normal'><a href="0">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>2 Contin?e por <b>SOMONTES AL PALACIO DE LA REAL QUINTA</b> durante  447.44 y  gire a la <b>izquierda</b> por <b>M-30 (CTRA DEL PARDO)</b></td></tr><tr><td>Distancia acumulada:</td><td>447.44</td></tr><tr><td><a href="0">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><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><td>Distancia acumulada:</td><td>2,768.02</td></tr><tr><td><a href="1,2,3">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-right.png"></td><td class='normal'>4 Contin?e por <b>LA ALBERCA</b> durante  355.99 y  gire a la <b>derecha</b> por <b>SOMONTES</b></td></tr><tr><td>Distancia acumulada:</td><td>3,124.01</td></tr><tr><td><a href="4,5,6">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>5 Contin?e por <b>SOMONTES</b> durante  136.05 y  gire a la <b>izquierda</b> por <b>TORREBELE?A</b></td></tr><tr><td>Distancia acumulada:</td><td>3,260.06</td></tr><tr><td><a href="7">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-right.png"></td><td class='normal'>6 Contin?e por <b>TORREBELE?A</b> durante  289.31 y  gire a la <b>derecha</b> por <b>SIGUERO</b></td></tr><tr><td>Distancia acumulada:</td><td>3,549.37</td></tr><tr><td><a href="8,9">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-right.png"></td><td class='normal'>7 Contin?e por <b>SIGUERO</b> durante  92.16 y  gire a la <b>derecha</b> por <b>NAVARREDONDA DE GREDOS</b></td></tr><tr><td>Distancia acumulada:</td><td>3,641.53</td></tr><tr><td><a href="10">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>8 Contin?e por <b>NAVARREDONDA DE GREDOS</b> durante  322.42 y  gire a la <b>izquierda</b> por <b>FRESNEDILLAS</b></td></tr><tr><td>Distancia acumulada:</td><td>3,963.95</td></tr><tr><td><a href="11">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>9 Contin?e por <b>FRESNEDILLAS</b> durante  315.69 y  gire a la <b>izquierda</b> por <b>BRAOJOS</b></td></tr><tr><td>Distancia acumulada:</td><td>4,279.64</td></tr><tr><td><a href="12,13">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>10 Contin?e por <b>BRAOJOS</b> durante  98.91 y  gire a la <b>izquierda</b> por <b>ARROYO DEL FRESNO</b></td></tr><tr><td>Distancia acumulada:</td><td>4,378.55</td></tr><tr><td><a href="14">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>11 Contin?e por <b>ARROYO DEL FRESNO</b> durante  1,506.38 y  gire a la <b>izquierda</b> por <b>BURGOS (MONTECARMELO)</b></td></tr><tr><td>Distancia acumulada:</td><td>5,884.93</td></tr><tr><td><a href="15,16">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>12 Contin?e por <b>BURGOS (MONTECARMELO)</b> durante  428.68 y  gire a la <b>izquierda</b> por <b>MONTIJA</b></td></tr><tr><td>Distancia acumulada:</td><td>6,313.61</td></tr><tr><td><a href="17">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-right.png"></td><td class='normal'>13 Contin?e por <b>MONTIJA</b> durante  999.9 y  gire a la <b>derecha</b> por <b>OTERUELO DEL VALLE</b></td></tr><tr><td>Distancia acumulada:</td><td>7,313.51</td></tr><tr><td><a href="18,19">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>14 Contin?e por <b>OTERUELO DEL VALLE</b> durante  95.17 y  gire a la <b>izquierda</b> por <b>RASCAFRIA</b></td></tr><tr><td>Distancia acumulada:</td><td>7,408.68</td></tr><tr><td><a href="20">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-right.png"></td><td class='normal'>15 Contin?e por <b>RASCAFRIA</b> durante  259.48 y  gire a la <b>derecha</b> por <b>CELEORAMA GOMEZ</b></td></tr><tr><td>Distancia acumulada:</td><td>7,668.16</td></tr><tr><td><a href="21">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/gtk-go-left.png"></td><td class='normal'>16 Contin?e por <b>CELEORAMA GOMEZ</b> durante  82.8 y  gire a la <b>izquierda</b> por <b>VILELA</b></td></tr><tr><td>Distancia acumulada:</td><td>7,750.96</td></tr><tr><td><a href="22">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/drapeau_arrivee.gif"></td><td>16. Llegada: MONTE CARMELO</td></tr><tr><td>Longitud:</td><td>9,020.31</td></tr><tr><td><a href="24">Ver sobre el mapa</a><td></tr></table>
20
 </body>
21
</html>
0 22

  
trunk/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: #0000FF;} --> 
8
</style>
9

  
10
</head>
11

  
12
<body>
13
<h1>Informe de Ruta:SOMONTES AL PALACIO DE LA REAL QUINTA-MONTE CARMELO</h1>
14
<br>Salida desde: <b>SOMONTES AL PALACIO DE LA REAL QUINTA</b><br>
15
Llegada a:<b> MONTE CARMELO</b><br>Longitud total del trayecto: <b>9,020.31</b>
16
<hr width ="70%">
17
<table>
18
<tr>
19
    <td><img src="images/drapeau_depart.gif" width="18" height="26"></td>
20
    <td class='normal'>1. Salir de:<b> SOMONTES AL PALACIO DE LA REAL QUINTA</b></td></tr><tr><td class='normal'><a href="images/0">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr>
21
    <td><img src="images/gtk-go-left.png" width="24" height="24"></td>
22
    <td class='normal'>2 Contin?e por <b>SOMONTES AL PALACIO DE LA REAL QUINTA</b> durante  447.44 y  gire a la <b>izquierda</b> por <b>M-30 (CTRA DEL PARDO)</b></td></tr><tr><td>Distancia acumulada:</td><td>447.44</td></tr><tr><td><a href="images/0">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><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><td>Distancia acumulada:</td><td>2,768.02</td></tr><tr><td><a href="images/1,2,3">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-right.png"></td><td class='normal'>4 Contin?e por <b>LA ALBERCA</b> durante  355.99 y  gire a la <b>derecha</b> por <b>SOMONTES</b></td></tr><tr><td>Distancia acumulada:</td><td>3,124.01</td></tr><tr><td><a href="images/4,5,6">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>5 Contin?e por <b>SOMONTES</b> durante  136.05 y  gire a la <b>izquierda</b> por <b>TORREBELE?A</b></td></tr><tr><td>Distancia acumulada:</td><td>3,260.06</td></tr><tr><td><a href="images/7">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-right.png"></td><td class='normal'>6 Contin?e por <b>TORREBELE?A</b> durante  289.31 y  gire a la <b>derecha</b> por <b>SIGUERO</b></td></tr><tr><td>Distancia acumulada:</td><td>3,549.37</td></tr><tr><td><a href="images/8,9">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-right.png"></td><td class='normal'>7 Contin?e por <b>SIGUERO</b> durante  92.16 y  gire a la <b>derecha</b> por <b>NAVARREDONDA DE GREDOS</b></td></tr><tr><td>Distancia acumulada:</td><td>3,641.53</td></tr><tr><td><a href="images/10">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>8 Contin?e por <b>NAVARREDONDA DE GREDOS</b> durante  322.42 y  gire a la <b>izquierda</b> por <b>FRESNEDILLAS</b></td></tr><tr><td>Distancia acumulada:</td><td>3,963.95</td></tr><tr><td><a href="images/11">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>9 Contin?e por <b>FRESNEDILLAS</b> durante  315.69 y  gire a la <b>izquierda</b> por <b>BRAOJOS</b></td></tr><tr><td>Distancia acumulada:</td><td>4,279.64</td></tr><tr><td><a href="images/12,13">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>10 Contin?e por <b>BRAOJOS</b> durante  98.91 y  gire a la <b>izquierda</b> por <b>ARROYO DEL FRESNO</b></td></tr><tr><td>Distancia acumulada:</td><td>4,378.55</td></tr><tr><td><a href="images/14">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>11 Contin?e por <b>ARROYO DEL FRESNO</b> durante  1,506.38 y  gire a la <b>izquierda</b> por <b>BURGOS (MONTECARMELO)</b></td></tr><tr><td>Distancia acumulada:</td><td>5,884.93</td></tr><tr><td><a href="images/15,16">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>12 Contin?e por <b>BURGOS (MONTECARMELO)</b> durante  428.68 y  gire a la <b>izquierda</b> por <b>MONTIJA</b></td></tr><tr><td>Distancia acumulada:</td><td>6,313.61</td></tr><tr><td><a href="images/17">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-right.png"></td><td class='normal'>13 Contin?e por <b>MONTIJA</b> durante  999.9 y  gire a la <b>derecha</b> por <b>OTERUELO DEL VALLE</b></td></tr><tr><td>Distancia acumulada:</td><td>7,313.51</td></tr><tr><td><a href="images/18,19">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>14 Contin?e por <b>OTERUELO DEL VALLE</b> durante  95.17 y  gire a la <b>izquierda</b> por <b>RASCAFRIA</b></td></tr><tr><td>Distancia acumulada:</td><td>7,408.68</td></tr><tr><td><a href="images/20">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-right.png"></td><td class='normal'>15 Contin?e por <b>RASCAFRIA</b> durante  259.48 y  gire a la <b>derecha</b> por <b>CELEORAMA GOMEZ</b></td></tr><tr><td>Distancia acumulada:</td><td>7,668.16</td></tr><tr><td><a href="images/21">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/gtk-go-left.png"></td><td class='normal'>16 Contin?e por <b>CELEORAMA GOMEZ</b> durante  82.8 y  gire a la <b>izquierda</b> por <b>VILELA</b></td></tr><tr><td>Distancia acumulada:</td><td>7,750.96</td></tr><tr><td><a href="images/22">Ver sobre el mapa</a><td></tr></table><hr width ="70%"><table><tr><td><img src="images/images/drapeau_arrivee.gif"></td><td>16. Llegada: MONTE CARMELO</td></tr><tr><td>Longitud:</td><td>9,020.31</td></tr><tr><td><a href="images/24">Ver sobre el mapa</a><td></tr></table>
23
 </body>
24
</html>
0 25

  
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/NetworkExtension.java
68 68
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
69 69
import com.iver.cit.gvsig.graph.core.IGraph;
70 70
import com.iver.cit.gvsig.graph.core.Network;
71
import com.iver.cit.gvsig.graph.core.NetworkLoader;
72
import com.iver.cit.gvsig.graph.core.NetworkRedLoader;
73
import com.iver.cit.gvsig.graph.core.NetworkWriter;
71
import com.iver.cit.gvsig.graph.core.loaders.NetworkLoader;
72
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
73
import com.iver.cit.gvsig.graph.core.writers.NetworkFileRedWriter;
74
import com.iver.cit.gvsig.graph.core.writers.NetworkGvTableWriter;
74 75
import com.iver.cit.gvsig.graph.gui.wizard.NetWizard;
75 76
import com.iver.cit.gvsig.graph.preferences.RoutePage;
76 77
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
......
200 201

  
201 202

  
202 203
	private void generateNetwork(FLyrVect lyr) {
203
		NetworkWriter netBuilder = new NetworkWriter();
204
		NetworkGvTableWriter netBuilder = new NetworkGvTableWriter();
204 205
		// Por ahora, a pelo, pero hay que sacar un cuadro
205 206
		// de di?logo para hecer el mapping.
206 207
		// Tambi?n un cuadro de di?logo para seleccionar
......
213 214
			netBuilder.setFieldType(fieldType);
214 215
			netBuilder.setFieldDist(fieldDist);
215 216
			netBuilder.setFieldSense(fieldSense);
217
			netBuilder.setFieldCost(fieldCost);
216 218
			DbfWriter nodeWriter = new DbfWriter();
217 219
			nodeWriter.setFile(new File("c:/nodes.dbf"));
218 220

  
......
222 224
			netBuilder.setEdgeWriter(edgeWriter);
223 225
			netBuilder.setNodeWriter(nodeWriter);
224 226

  
225
			netBuilder.writeNetwork(true);
227
			netBuilder.writeNetwork();
226 228
		} catch (DriverException e1) {
227 229
			// TODO Auto-generated catch block
228 230
			e1.printStackTrace();
......
237 239
	class GenerateRedNetworkTask extends AbstractMonitorableTask{
238 240
		FLyrVect layer;
239 241
		File redFile;
240
		NetworkWriter netBuilder;
242
		NetworkFileRedWriter netBuilder;
241 243
		/**
242 244
		 * Constructor
243 245
		 * */
244
		GenerateRedNetworkTask(FLyrVect layer, File redFile, NetworkWriter netBuilder){
246
		GenerateRedNetworkTask(FLyrVect layer, File redFile, NetworkFileRedWriter netBuilder){
245 247
			this.layer = layer;
246 248
			this.redFile = redFile;
247 249
			this.netBuilder = netBuilder;
......
261 263
		}
262 264
		
263 265
		public void run() throws Exception {
264
			netBuilder.createRedFile(layer, redFile,  this);
266
			netBuilder.setLayer(layer);
267
			netBuilder.setCancellableMonitorable(this);
268
			netBuilder.setRedFile(redFile);
269
			netBuilder.writeNetwork();
265 270
			JOptionPane.showMessageDialog(null, PluginServices.getText(this, "done"));
266 271
		}	
267 272
		
......
283 288
	
284 289
	private void generateRedNetwork(FLyrVect lyr) {
285 290
		lyr.createSpatialIndex();
286
		NetworkWriter netBuilder = new NetworkWriter();
291
		NetworkFileRedWriter netBuilder = new NetworkFileRedWriter();
287 292
		// Por ahora, a pelo, pero hay que sacar un cuadro
288 293
		// de di?logo para hecer el mapping.
289 294
		// Tambi?n un cuadro de di?logo para seleccionar
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/core/NetworkRedLoader.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.graph.core;
42

  
43
import java.io.File;
44
import java.io.FileNotFoundException;
45
import java.io.IOException;
46
import java.io.RandomAccessFile;
47
import java.nio.ByteOrder;
48
import java.nio.MappedByteBuffer;
49
import java.nio.channels.FileChannel;
50
import java.util.ArrayList;
51

  
52
import edu.uci.ics.jung.graph.Graph;
53
import edu.uci.ics.jung.graph.Vertex;
54
import edu.uci.ics.jung.graph.decorators.Indexer;
55
import edu.uci.ics.jung.graph.impl.DirectedSparseEdge;
56
import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
57
import edu.uci.ics.jung.graph.impl.SparseGraph;
58

  
59
/**
60
 * @author fjp
61
 * 
62
 * Primero vienen los arcos, y luego los nodos. En la cabecera, 3 enteros
63
 * con el numero de tramos, el de arcos y el de nodos.
64
 *
65
 */
66
public class NetworkRedLoader implements INetworkLoader {
67
	
68
	private File netFile = new File("c:/ejes.red");
69

  
70
	public IGraph loadNetwork() {
71
		
72
		long t1 = System.currentTimeMillis();
73
		
74
		int numArcs;
75
		int numEdges;
76
		int numNodes;
77
		
78
		short sentidoDigit; // => 1 en esa direcci?n. 0=> Al contrario. SOLO
79
		// SE UTILIZA PARA LOS CALCULOS POR IDTRAMO Y
80
		// PORCENTAJE
81
		// PARA SABER SI EST? M?S CERCA DE UN NODO O DEL OTRO.
82

  
83

  
84
			RandomAccessFile file;
85
			try {
86
				file = new RandomAccessFile(netFile.getPath(),
87
						"r");
88
				FileChannel channel = file.getChannel();
89
				MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
90
				buf.order(ByteOrder.LITTLE_ENDIAN);
91
	
92
				numArcs = buf.getInt();
93
				numEdges = buf.getInt();
94
				numNodes = buf.getInt();
95
		
96
				GvGraph g = new GvGraph(numArcs, numEdges, numNodes);
97

  
98
				// Nodes
99
				buf.position(30*numEdges + 12);
100
				for (int i=0; i < numNodes; i++)
101
				{
102
					GvNode node = readNode(buf);
103
					g.addNode(node);
104
				}
105
				// Arcos			
106
				buf.position(12);
107
				for (int i=0; i < numEdges; i++)
108
				{
109
					GvEdge edge = readEdge(buf);
110
					edge.setIdEdge(i);
111
					g.addEdge(edge);
112
					GvNode node = g.getNodeByID(edge.getIdNodeOrig());
113
					node.getEnlaces().add(edge);
114
					EdgePair edgePair = g.getEdgesByIdArc(edge.getIdArc());
115
					if (edgePair == null)
116
					{
117
						edgePair = new EdgePair();						
118
						g.addEdgePair(edgePair);
119
					}
120
					if (edge.getDirec() == 1)
121
						edgePair.setIdEdge(i);
122
					else
123
						edgePair.setIdInverseEdge(i);
124
					
125
				}
126
			
127
			long t2 = System.currentTimeMillis();
128
			System.out.println("Tiempo de carga: " + (t2-t1) + " msecs");
129
			System.out.println("NumEdges = " + g.numEdges());
130
			return g;
131
			} catch (FileNotFoundException e) {
132
				// TODO Auto-generated catch block
133
				e.printStackTrace();
134
			} catch (IOException e) {
135
				// TODO Auto-generated catch block
136
				e.printStackTrace();
137
			}
138

  
139
		return null;
140
	}
141
	
142
	public Graph loadJungNetwork()
143
	{
144
		SparseGraph g = new SparseGraph();
145
		long t1 = System.currentTimeMillis();
146
		
147
		RandomAccessFile file;
148
		try {
149
			file = new RandomAccessFile(netFile.getPath(),
150
					"r");
151
			FileChannel channel = file.getChannel();
152
			MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
153
			buf.order(ByteOrder.LITTLE_ENDIAN);
154

  
155
			int numArcs = buf.getInt();
156
			int numEdges = buf.getInt();
157
			int numNodes = buf.getInt();
158
			
159
			// Nodes
160
			buf.position(24*numEdges + 12);
161
			for (int i=0; i < numNodes; i++)
162
			{
163
				GvNode node = readNode(buf);
164
				
165
				Vertex v = new DirectedSparseVertex();
166
//				v.addUserDatum("ID", node.idNode, UserData.CLONE);
167
//				v.addUserDatum("X", node.x, UserData.CLONE);
168
//				v.addUserDatum("Y", node.y, UserData.CLONE);
169
	//			v_locations.setLocation(v, new Point2D.Double(x.doubleValue(),y.doubleValue()));
170
				g.addVertex(v);				
171
			}
172
			Indexer indexer = Indexer.getIndexer(g);
173
		
174
			buf.position(12);
175
			for (int i=0; i < numEdges; i++)
176
			{
177
				GvEdge edge = readEdge(buf);
178
				
179
				int nodeOrig = edge.getIdNodeOrig();
180
				int nodeEnd = edge.getIdNodeEnd();
181
				
182
				Vertex vFrom = (Vertex) indexer.getVertex(nodeOrig);
183
				Vertex vTo = (Vertex) indexer.getVertex(nodeEnd);
184
				
185
				DirectedSparseEdge edgeJ = new DirectedSparseEdge(vFrom, vTo);
186
				g.addEdge(edgeJ);
187
			}
188
			long t2 = System.currentTimeMillis();
189
			System.out.println("Tiempo de carga: " + (t2-t1) + " msecs");
190
			return g;
191
		} catch (FileNotFoundException e) {
192
			// TODO Auto-generated catch block
193
			e.printStackTrace();
194
		} catch (IOException e) {
195
			// TODO Auto-generated catch block
196
			e.printStackTrace();
197
		}
198
		return null;
199
	}
200

  
201
	private GvNode readNode(MappedByteBuffer buf) {
202
		GvNode node = new GvNode();
203
		node.setIdNode(buf.getInt());
204
		node.setX(buf.getFloat());
205
		node.setY(buf.getFloat());
206
		return node;
207
	}
208

  
209
	private GvEdge readEdge(MappedByteBuffer buf) {
210
		GvEdge edge = new GvEdge();
211
		// memcpy(&Arcos[link_num].idTramo,puntero,sizeof(long));
212
		edge.setIdArc(buf.getInt());
213

  
214
		
215
		// Sentido de digitalizaci?n.Un 1 indica que va en ese sentido, un cero al contrario.
216
		// memcpy(&Arcos[link_num].sentido,puntero,sizeof(int));
217
		edge.setDirec(buf.getInt());
218

  
219
		// idNodeOrig
220
		edge.setIdNodeOrig(buf.getInt());
221
		// memcpy(&node_num1,puntero,sizeof(long));
222
		
223
		// idNodeEnd
224
		edge.setIdNodeEnd(buf.getInt());
225
//		memcpy(&node_num2,puntero,sizeof(long));
226

  
227
		// Read the link costs.
228
		// Type
229
		edge.setType(buf.getInt());
230
//		memcpy(&Arcos[link_num].TipoTramo,puntero,sizeof(int));
231

  
232
		// Distance
233
		edge.setDistance(buf.getDouble());
234
		edge.setWeight(buf.getDouble());
235
		
236
//		memcpy(&Arcos[link_num].Coste2,puntero,sizeof(float));
237

  
238
//		pNodo1 = &Nodos[node_num1];
239
//		Arcos[link_num].idNodo1 = node_num1;
240
//
241
//		Arcos[link_num].idNodo2 = node_num2;
242
		// pNodo2->Enlaces.Add(link_num);
243

  
244
//		// NUEVO 11-JUL-2002
245
//			if (Arcos[link_num].sentido)
246
//			IndiceArcos[Arcos[link_num].idTramo].idArco = link_num;
247
//		else
248
//			IndiceArcos[Arcos[link_num].idTramo].idContraArco = link_num;
249
//
250
//		// NUEVO 27-JUL-2003
251
//		Arcos[link_num].numSoluc = 0;
252
//
253
//		// NUEVO 23_2_2005
254
//		CreaConectores(link_num);
255
		return edge;
256
	}
257

  
258
	/**
259
	 * @param args
260
	 */
261
	public static void main(String[] args) {
262
		NetworkRedLoader redLoader = new NetworkRedLoader();
263
		
264
		redLoader.loadNetwork();
265
		redLoader.loadJungNetwork();
266

  
267
	}
268

  
269
	public File getNetFile() {
270
		return netFile;
271
	}
272

  
273
	public void setNetFile(File netFile) {
274
		this.netFile = netFile;
275
	}
276

  
277
}
278

  
279

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

  
43
import java.awt.geom.Point2D;
44
import java.io.File;
45

  
46
import com.hardcode.driverManager.Driver;
47
import com.hardcode.driverManager.DriverLoadException;
48
import com.hardcode.driverManager.DriverManager;
49
import com.hardcode.driverManager.DriverValidation;
50
import com.hardcode.gdbms.engine.data.DataSource;
51
import com.hardcode.gdbms.engine.data.DataSourceFactory;
52
import com.hardcode.gdbms.engine.data.NoSuchTableException;
53
import com.hardcode.gdbms.engine.data.driver.DBDriver;
54
import com.hardcode.gdbms.engine.data.driver.DriverException;
55
import com.hardcode.gdbms.engine.data.driver.FileDriver;
56
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
57
import com.hardcode.gdbms.engine.values.NumericValue;
58
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
59
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
60

  
61
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance;
62
import edu.uci.ics.jung.graph.ArchetypeVertex;
63
import edu.uci.ics.jung.graph.Graph;
64
import edu.uci.ics.jung.graph.Vertex;
65
import edu.uci.ics.jung.graph.decorators.Indexer;
66
import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
67
import edu.uci.ics.jung.graph.impl.SparseGraph;
68
import edu.uci.ics.jung.utils.UserData;
69
import edu.uci.ics.jung.visualization.DefaultSettableVertexLocationFunction;
70
import edu.uci.ics.jung.visualization.SettableVertexLocationFunction;
71

  
72
public class NetworkLoader implements INetworkLoader {
73
	
74
	private String fieldNodeId = "NODEID";
75
	private String fieldNodeX = "X";
76
	private String fieldNodeY = "Y";
77

  
78
	private String fieldArcId = "ARCID";
79
	private String fieldDirection = "DIRECTION";
80
	private String fieldNodeOrig = "NODEORIGIN";
81
	private String fieldNodeEnd = "NODEEND";
82
	private String fieldType = "TYPE";
83
	private String fieldDist = "DIST";
84
	private String fieldCost = "COST";
85

  
86
	private SelectableDataSource nodeReader;
87
	private SelectableDataSource edgeReader;
88
	
89
	private Indexer indexer;
90
	
91
	private boolean bUseCostField;
92
	
93
	/**
94
     * The user data key used to retrieve the vertex locations (if any) defined by this class.
95
     */
96
    public static final String LOCATIONS = "jung.io.GvSIGNetReader.LOCATIONS";
97
    
98
	protected SettableVertexLocationFunction v_locations = new DefaultSettableVertexLocationFunction();
99

  
100

  
101
	/**
102
	 * By default, the fields are:
103
	 * private String fieldNodeId = "NODEID";
104
	 * 	 fieldNodeX = "X";
105
	 * 	 fieldNodeY = "Y";
106
	 * 
107
	 * 	 fieldArcId = "NODEID";
108
	 * 	 fieldDirection = "X";
109
	 * 	 fieldNodeOrig = "Y";
110
	 * 	 fieldNodeEnd = "NODEORIGIN";
111
	 * 	 fieldType = "NODEEND";
112
	 * 	 fieldDist = "DIST";
113
	 * 
114
	 * If you need to change any, use the correspondant "setFieldXXXX"
115
	 * BEFORE calling loadNetwork. And remember to set nodeReader and 
116
	 * edgeReader also.
117
	 */
118
	public NetworkLoader(boolean bUseCostField) {
119
		this.bUseCostField = bUseCostField;
120
	}
121

  
122
	
123
	public String getFieldArcId() {
124
		return fieldArcId;
125
	}
126

  
127
	public void setFieldArcId(String fieldArcId) {
128
		this.fieldArcId = fieldArcId;
129
	}
130

  
131
	public String getFieldDirection() {
132
		return fieldDirection;
133
	}
134

  
135
	public void setFieldDirection(String fieldDirection) {
136
		this.fieldDirection = fieldDirection;
137
	}
138

  
139
	public String getFieldDist() {
140
		return fieldDist;
141
	}
142

  
143
	public void setFieldDist(String fieldDist) {
144
		this.fieldDist = fieldDist;
145
	}
146

  
147
	public String getFieldNodeEnd() {
148
		return fieldNodeEnd;
149
	}
150

  
151
	public void setFieldNodeEnd(String fieldNodeEnd) {
152
		this.fieldNodeEnd = fieldNodeEnd;
153
	}
154

  
155
	public String getFieldNodeId() {
156
		return fieldNodeId;
157
	}
158

  
159
	public void setFieldNodeId(String fieldNodeId) {
160
		this.fieldNodeId = fieldNodeId;
161
	}
162

  
163
	public String getFieldNodeOrig() {
164
		return fieldNodeOrig;
165
	}
166

  
167
	public void setFieldNodeOrig(String fieldNodeOrig) {
168
		this.fieldNodeOrig = fieldNodeOrig;
169
	}
170

  
171
	public String getFieldNodeX() {
172
		return fieldNodeX;
173
	}
174

  
175
	public void setFieldNodeX(String fieldNodeX) {
176
		this.fieldNodeX = fieldNodeX;
177
	}
178

  
179
	public String getFieldNodeY() {
180
		return fieldNodeY;
181
	}
182

  
183
	public void setFieldNodeY(String fieldNodeY) {
184
		this.fieldNodeY = fieldNodeY;
185
	}
186

  
187
	public String getFieldType() {
188
		return fieldType;
189
	}
190

  
191
	public void setFieldType(String fieldType) {
192
		this.fieldType = fieldType;
193
	}
194

  
195
	public void setEdgeReader(SelectableDataSource edgeReader) {
196
		this.edgeReader = edgeReader;
197
	}
198

  
199
	public void setNodeReader(SelectableDataSource nodeReader) {
200
		this.nodeReader = nodeReader;
201
	}
202

  
203
	/**
204
	 * @param args
205
	 */
206
	public static void main(String[] args) {
207
		NetworkLoader netLoader = new NetworkLoader(false);
208

  
209
		//Setup de los drivers
210
		DriverManager dm = new DriverManager();
211
		dm.setValidation(new DriverValidation() {
212
				public boolean validate(Driver d) {
213
					return ((d instanceof ObjectDriver) ||
214
					(d instanceof FileDriver) ||
215
					(d instanceof DBDriver));
216
				}
217
			});
218
		dm.loadDrivers(new File("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"));
219

  
220
		//Setup del factory de DataSources
221
        DataSourceFactory dsf = LayerFactory.getDataSourceFactory();
222
		dsf.setDriverManager(dm);
223

  
224
		//Setup de las tablas
225
		dsf.addFileDataSource("gdbms dbf driver", "nodes", "c:/nodes.dbf");
226
		dsf.addFileDataSource("gdbms dbf driver", "edges", "c:/edges.dbf");
227

  
228
        DataSource dsNodes;
229
		try {
230
			dsNodes = dsf.createRandomDataSource("nodes",
231
			        DataSourceFactory.MANUAL_OPENING);
232
	
233
	        DataSource dsEdges = dsf.createRandomDataSource("edges",
234
	                DataSourceFactory.MANUAL_OPENING);
235
		
236
				
237
			SelectableDataSource sdsNodes = new SelectableDataSource(dsNodes);
238
			SelectableDataSource sdsEdges = new SelectableDataSource(dsEdges);
239
			
240
			netLoader.setNodeReader(sdsNodes);
241
			netLoader.setEdgeReader(sdsEdges);
242
			
243
			
244
			Graph g = netLoader.loadJungNetwork();
245
			
246
			System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges());
247
			
248
			// Probamos la algoritmia: distancia entre nodo 1 y nodo 1000
249
			DijkstraDistance distCalculator = new DijkstraDistance(g, new EdgeWeightLabeller());
250
			ArchetypeVertex vOrig = netLoader.indexer.getVertex(1);
251
			ArchetypeVertex vEnd = netLoader.indexer.getVertex(1000);
252
			long t1 = System.currentTimeMillis();
253
			Number dist = distCalculator.getDistance(vOrig, vEnd);
254
			long t2 = System.currentTimeMillis();
255
			
256
			
257
			System.out.println("dist =" + dist + " meters. msecs: " + (t2-t1));
258
			System.out.println(vOrig + " - " + vEnd);
259
			System.out.println(vOrig.getUserDatum("X") + ", " + vOrig.getUserDatum("Y")
260
							+ " - " + vEnd.getUserDatum("X") + ", " + vEnd.getUserDatum("Y"));
261
			
262
		} catch (DriverLoadException e) {
263
			// TODO Auto-generated catch block
264
			e.printStackTrace();
265
		} catch (NoSuchTableException e) {
266
			// TODO Auto-generated catch block
267
			e.printStackTrace();
268
		} catch (DriverException e) {
269
			// TODO Auto-generated catch block
270
			e.printStackTrace();
271
		}
272

  
273
	}
274

  
275
	public Graph loadJungNetwork() {
276
		try {
277
			int fieldIndexIdNode = nodeReader.getFieldIndexByName(fieldNodeId);
278
			int fieldIndexX = nodeReader.getFieldIndexByName(fieldNodeX);;
279
			int fieldIndexY = nodeReader.getFieldIndexByName(fieldNodeY);;
280

  
281
			int fieldIndexArcID = edgeReader.getFieldIndexByName(fieldArcId);
282
			int fieldIndexDirection = edgeReader.getFieldIndexByName(fieldDirection);
283
			int fieldIndexNodeOrig = edgeReader.getFieldIndexByName(fieldNodeOrig);
284
			int fieldIndexNodeEnd = edgeReader.getFieldIndexByName(fieldNodeEnd);
285
			int fieldIndexType = edgeReader.getFieldIndexByName(fieldType);
286
			int fieldIndexDist = edgeReader.getFieldIndexByName(fieldDist);
287
			
288
			
289
			SparseGraph g = new SparseGraph();
290
//			g.getEdgeConstraints().clear();
291
			long t1 = System.currentTimeMillis();
292
			
293
			// Mirar NumberEdgeVAlue e Indexer
294
			for (int i=0; i < nodeReader.getRowCount(); i++)
295
			{
296
				NumericValue id = (NumericValue) nodeReader.getFieldValue(i, fieldIndexIdNode);
297
				NumericValue x = (NumericValue) nodeReader.getFieldValue(i, fieldIndexX);
298
				NumericValue y = (NumericValue) nodeReader.getFieldValue(i, fieldIndexY);
299
				Vertex v = new DirectedSparseVertex();
300
				v.addUserDatum("ID", id, UserData.CLONE);
301
				v.addUserDatum("X", x, UserData.CLONE);
302
				v.addUserDatum("Y", y, UserData.CLONE);
303
				v_locations.setLocation(v, new Point2D.Double(x.doubleValue(),y.doubleValue()));
304
				g.addVertex(v);				
305
			}
306
			indexer = Indexer.getIndexer(g);
307
			
308
			for (int i=0; i < edgeReader.getRowCount(); i++)
309
			{
310
				NumericValue arcID = (NumericValue) edgeReader.getFieldValue(i, fieldIndexArcID);
311
				NumericValue direc = (NumericValue) edgeReader.getFieldValue(i, fieldIndexDirection);
312
				NumericValue nodeOrig = (NumericValue) edgeReader.getFieldValue(i, fieldIndexNodeOrig);
313
				NumericValue nodeEnd = (NumericValue) edgeReader.getFieldValue(i, fieldIndexNodeEnd);
314
				NumericValue type = (NumericValue) edgeReader.getFieldValue(i, fieldIndexType);
315
				NumericValue dist = (NumericValue) edgeReader.getFieldValue(i, fieldIndexDist);
316
				
317
				Vertex vFrom = (Vertex) indexer.getVertex(nodeOrig.intValue());
318
				Vertex vTo = (Vertex) indexer.getVertex(nodeEnd.intValue());
319
				
320
				FEdge edge = new FEdge(vFrom, vTo);
321
				edge.setArcID(arcID.intValue());
322
				edge.setDirection(direc.intValue());
323
				edge.setIdNodeOrig(nodeOrig.intValue());
324
				edge.setIdNodeEnd(nodeEnd.intValue());
325
				edge.setType(type.intValue());
326
				edge.setWeight(dist.doubleValue());
327
				
328
				g.addEdge(edge);
329
			}
330
			long t2 = System.currentTimeMillis();
331
			System.out.println("Tiempo de carga desde nodes.dbf y edges.dbf y generando JUNG network: " + (t2-t1) + " msecs");
332
			return g;
333
		} catch (DriverException e) {
334
			// TODO Auto-generated catch block
335
			e.printStackTrace();
336
		}
337
		return null;
338
	}
339

  
340

  
341
	public IGraph loadNetwork() {
342
		try {
343
			int fieldIndexIdNode = nodeReader.getFieldIndexByName(fieldNodeId);
344
			int fieldIndexX = nodeReader.getFieldIndexByName(fieldNodeX);;
345
			int fieldIndexY = nodeReader.getFieldIndexByName(fieldNodeY);;
346

  
347
			int fieldIndexArcID = edgeReader.getFieldIndexByName(fieldArcId);
348
			int fieldIndexDirection = edgeReader.getFieldIndexByName(fieldDirection);
349
			int fieldIndexNodeOrig = edgeReader.getFieldIndexByName(fieldNodeOrig);
350
			int fieldIndexNodeEnd = edgeReader.getFieldIndexByName(fieldNodeEnd);
351
			int fieldIndexType = edgeReader.getFieldIndexByName(fieldType);
352
			int fieldIndexDist = edgeReader.getFieldIndexByName(fieldDist);
353
			int fieldIndexCost = edgeReader.getFieldIndexByName(fieldCost);
354
			
355
			
356
			GvGraph g = new GvGraph();
357
			long t1 = System.currentTimeMillis();
358
			
359
			// Mirar NumberEdgeVAlue e Indexer
360
			for (int i=0; i < nodeReader.getRowCount(); i++)
361
			{
362
				NumericValue id = (NumericValue) nodeReader.getFieldValue(i, fieldIndexIdNode);
363
				NumericValue x = (NumericValue) nodeReader.getFieldValue(i, fieldIndexX);
364
				NumericValue y = (NumericValue) nodeReader.getFieldValue(i, fieldIndexY);
365
				GvNode node = new GvNode();
366
				node.setX(x.doubleValue());
367
				node.setY(y.doubleValue());
368
				node.setIdNode(i);
369
				g.addNode(node);				
370
			}
371
			
372
			for (int i=0; i < edgeReader.getRowCount(); i++)
373
			{
374
				NumericValue arcID = (NumericValue) edgeReader.getFieldValue(i, fieldIndexArcID);
375
				NumericValue direc = (NumericValue) edgeReader.getFieldValue(i, fieldIndexDirection);
376
				NumericValue nodeOrig = (NumericValue) edgeReader.getFieldValue(i, fieldIndexNodeOrig);
377
				NumericValue nodeEnd = (NumericValue) edgeReader.getFieldValue(i, fieldIndexNodeEnd);
378
				NumericValue type = (NumericValue) edgeReader.getFieldValue(i, fieldIndexType);
379
				NumericValue dist = (NumericValue) edgeReader.getFieldValue(i, fieldIndexDist);
380
				
381
				GvEdge edge = new GvEdge();
382
				edge.setIdArc(arcID.intValue());
383
				edge.setIdEdge(i);
384
				edge.setDirec(direc.intValue());
385
				edge.setIdNodeOrig(nodeOrig.intValue());
386
				edge.setIdNodeEnd(nodeEnd.intValue());
387
				edge.setType(type.intValue());
388
				edge.setDistance(dist.doubleValue());
389
				if (bUseCostField)
390
				{
391
					NumericValue cost = (NumericValue) edgeReader.getFieldValue(i, fieldIndexCost);
392
					edge.setWeight(cost.doubleValue());
393
				}
394
				
395
				g.addEdge(edge);
396
			}
397
			long t2 = System.currentTimeMillis();
398
			System.out.println("Tiempo de carga desde nodes.dbf y edges.dbf y generando JUNG network: " + (t2-t1) + " msecs");
399
			return g;
400
		} catch (DriverException e) {
401
			// TODO Auto-generated catch block
402
			e.printStackTrace();
403
		}
404
		return null;
405

  
406
	}
407

  
408

  
409
	public String getFieldCost() {
410
		return fieldCost;
411
	}
412

  
413

  
414
	public void setFieldCost(String fieldCost) {
415
		this.fieldCost = fieldCost;
416
	}
417

  
418

  
419
	public Indexer getIndexer() {
420
		return indexer;
421
	}
422

  
423
}
424

  
425

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

  
43
import java.io.File;
44
import java.io.FileNotFoundException;
45
import java.io.IOException;
46
import java.io.RandomAccessFile;
47
import java.nio.ByteOrder;
48
import java.sql.Types;
49
import java.util.ArrayList;
50
import java.util.Hashtable;
51

  
52
import javax.imageio.stream.FileImageOutputStream;
53

  
54
import com.hardcode.gdbms.engine.values.IntValue;
55
import com.hardcode.gdbms.engine.values.NumericValue;
56
import com.hardcode.gdbms.engine.values.Value;
57
import com.hardcode.gdbms.engine.values.ValueFactory;
58
import com.iver.cit.gvsig.fmap.DriverException;
59
import com.iver.cit.gvsig.fmap.core.DefaultRow;
60
import com.iver.cit.gvsig.fmap.core.FShape;
61
import com.iver.cit.gvsig.fmap.core.IGeometry;
62
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
63
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
64
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
65
import com.iver.cit.gvsig.fmap.drivers.TableDefinition;
66
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited;
67
import com.iver.cit.gvsig.fmap.edition.EditionException;
68
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
69
import com.iver.cit.gvsig.fmap.edition.IWriter;
70
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
71
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
72
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
73
import com.iver.utiles.swing.threads.CancellableMonitorable;
74
import com.vividsolutions.jts.geom.Coordinate;
75
import com.vividsolutions.jts.geom.Geometry;
76

  
77
/**
78
 * @author fjp
79
 *
80
 * 
81
 */
82
public class NetworkWriter {
83

  
84
	private FLyrVect lyr;
85

  
86
	private String fieldType;
87

  
88
	private String fieldDist;
89
	
90
	private String fieldCost;
91

  
92
	private String fieldSense;
93

  
94
	private IWriter nodeWriter;
95

  
96
	private IWriter edgeWriter;
97

  
98
	private FieldDescription[] nodeFields;
99

  
100
	private FieldDescription[] edgeFields;
101

  
102
	public NetworkWriter() {
103
		
104
		// Set up fields for table nodes
105
		nodeFields = new FieldDescription[3];
106
		FieldDescription fieldNodeId = new FieldDescription();
107
		fieldNodeId.setFieldName("NODEID");
108
		fieldNodeId.setFieldType(Types.INTEGER);
109

  
110
		FieldDescription fieldX = new FieldDescription();
111
		fieldX.setFieldName("X");
112
		fieldX.setFieldType(Types.DOUBLE);
113
		fieldX.setFieldDecimalCount(2);
114

  
115
		FieldDescription fieldY = new FieldDescription();
116
		fieldY.setFieldName("Y");
117
		fieldY.setFieldType(Types.DOUBLE);
118
		fieldY.setFieldDecimalCount(2);
119
		
120
		nodeFields[0] = fieldNodeId;
121
		nodeFields[1] = fieldX;
122
		nodeFields[2] = fieldY;
123

  
124
		
125
		// Set up fields for table edges
126
		edgeFields = new FieldDescription[7];
127

  
128
		// ID_TRAMO ORIGINAL!!!
129
		FieldDescription fieldArcID = new FieldDescription();
130
		fieldArcID.setFieldName("ArcID");
131
		fieldArcID.setFieldType(Types.INTEGER);
132

  
133
		FieldDescription fieldDirection = new FieldDescription();
134
		fieldDirection.setFieldName("Direction");
135
		fieldDirection.setFieldType(Types.SMALLINT);
136
		
137
		FieldDescription fieldNodeOrigin = new FieldDescription();
138
		fieldNodeOrigin.setFieldName("NodeOrigin");
139
		fieldNodeOrigin.setFieldType(Types.INTEGER);
140
		FieldDescription fieldNodeEnd = new FieldDescription();
141
		fieldNodeEnd.setFieldName("NodeEnd");
142
		fieldNodeEnd.setFieldType(Types.INTEGER);
143

  
144
		FieldDescription fieldType = new FieldDescription();
145
		fieldType.setFieldName("Type");
146
		fieldType.setFieldType(Types.SMALLINT);
147

  
148
		FieldDescription fieldDistanceDist = new FieldDescription();
149
		fieldDistanceDist.setFieldName("Dist");
150
		fieldDistanceDist.setFieldType(Types.DOUBLE);
151
		
152
		FieldDescription fieldDistanceCost = new FieldDescription();
153
		fieldDistanceCost.setFieldName("Cost");
154
		fieldDistanceCost.setFieldType(Types.DOUBLE);
155
		
156
		edgeFields[0] = fieldArcID;
157
		edgeFields[1] = fieldDirection;
158
		edgeFields[2] = fieldNodeOrigin;
159
		edgeFields[3] = fieldNodeEnd;
160
		edgeFields[4] = fieldType;
161
		edgeFields[5] = fieldDistanceDist;
162
		edgeFields[6] = fieldDistanceCost;
163
	}
164

  
165
	public FLyrVect getLayer() {
166
		return lyr;
167
	}
168

  
169
	public void setLayer(FLyrVect lyr) {
170
		this.lyr = lyr;
171
	}
172
	
173

  
174

  
175
	/**
176
	 * We iterate by each geometry and add Nodes and Edges using writers. Each
177
	 * node must have its own ID.
178
	 * 
179
	 * @throws DriverIOException
180
	 * @throws EditionException
181
	 * @throws DriverException
182
	 * 
183
	 */
184
	public void writeNetwork(boolean bUseCostField) throws EditionException,
185
			DriverException {
186
		
187
		double distance;
188
		double cost;
189
		short arcType;
190
		int direction;
191
		int i;
192
		int idNodo1, idNodo2, nodeCount, edgeCount;
193
		short sentidoDigit; // => 1 en esa direcci?n. 0=> Al contrario. SOLO
194
		// SE UTILIZA PARA LOS CALCULOS POR IDTRAMO Y
195
		// PORCENTAJE
196
		// PARA SABER SI EST? M?S CERCA DE UN NODO O DEL OTRO.
197

  
198
		
199
		VectorialAdapter adapter = (VectorialAdapter) lyr.getSource();
200

  
201
		try {
202
			int numEntities = adapter.getShapeCount();
203
			Hashtable nodeHash = new Hashtable();
204
			Value[] values = new Value[3];
205

  
206
			SelectableDataSource sds = lyr.getRecordset();
207
			
208
			int senseFieldIndex = sds.getFieldIndexByName(fieldSense);
209
			int distFieldIndex = sds.getFieldIndexByName(fieldDist);
210
			int costFieldIndex = sds.getFieldIndexByName(fieldCost);
211
			int typeFieldIndex = sds.getFieldIndexByName(fieldType);
212
			if (typeFieldIndex == -1) {
213
				throw new RuntimeException("Field invalid:" + fieldType);
214
			}
215
			if (distFieldIndex == -1) {
216
				throw new RuntimeException("Field invalid:" + fieldDist);
217
			}
218

  
219
			// We create a table definition for node table.
220
			ITableDefinition nodesTableDef = new TableDefinition();
221
			nodesTableDef.setFieldsDesc(nodeFields);
222
			nodesTableDef.setName("Nodes");
223

  
224
			// We create a table definition for edges table.
225
			ITableDefinition edgeTableDef = new TableDefinition();
226
			edgeTableDef.setFieldsDesc(edgeFields);
227
			edgeTableDef.setName("Edges");
228

  
229
			nodeWriter.initialize(nodesTableDef);
230
			edgeWriter.initialize(edgeTableDef);
231
			
232
			nodeWriter.preProcess();
233
			edgeWriter.preProcess();
234
			
235
			edgeCount = 0;
236
			nodeCount = 0; 
237

  
238
			for (i = 0; i < numEntities; i++) {
239
				IGeometry geom = adapter.getShape(i);
240
				Geometry jtsGeom = geom.toJTSGeometry();
241
				Coordinate[] coords = jtsGeom.getCoordinates();
242
				Coordinate c1 = coords[0];
243
				Coordinate c2 = coords[coords.length - 1];
244

  
245
				NodeGv nodeAux;
246
				if (!nodeHash.containsKey(c1)) // No est?.
247
				{
248
					idNodo1 = nodeCount++;
249
					nodeAux = new NodeGv(c1, idNodo1);
250
					nodeHash.put(c1, nodeAux);
251
					writeNode(nodeAux);
252
				} else {
253
					nodeAux = (NodeGv) nodeHash.get(c1);
254
				}
255
				idNodo1 = nodeAux.getId().intValue();
256

  
257
				if (!nodeHash.containsKey(c2)) // No est?.
258
				{
259
					idNodo2 = nodeCount++;
260
					nodeAux = new NodeGv(c2, idNodo2);
261
					nodeHash.put(c2, nodeAux);
262
					writeNode(nodeAux);
263
				} else {
264
					nodeAux = (NodeGv) nodeHash.get(c2);
265
				}
266
				idNodo2 = nodeAux.getId().intValue();
267

  
268
				NumericValue valAux = (NumericValue) sds.getFieldValue(i,
269
						typeFieldIndex);
270
				arcType = valAux.shortValue();
271
				valAux = (NumericValue) sds.getFieldValue(i, distFieldIndex);
272
				distance = valAux.doubleValue();
273
				if (bUseCostField)
274
				{
275
					valAux = (NumericValue) sds.getFieldValue(i, costFieldIndex);
276
					cost = valAux.doubleValue();					
277
				}
278
				else
279
					cost = distance;
280

  
281
				direction = -1;
282

  
283
				if (senseFieldIndex == -1)
284
					direction = 3; // 3-> Doble sentido, 1-> seg?n viene, 2 ->
285
				// al rev?s, cualquier otro valor-> No hay
286
				// arco
287
				else {
288
					valAux = (NumericValue) sds.getFieldValue(i,
289
							senseFieldIndex);
290
					direction = valAux.shortValue();
291
				}
292

  
293
				if (direction == 3) {
294
					sentidoDigit = 1; // En esa direcci?n
295
					writeEdge(i, sentidoDigit, idNodo1, idNodo2, arcType,
296
							distance, cost);
297
					edgeCount++;
298

  
299
					sentidoDigit = 0;
300
					writeEdge(i, sentidoDigit, idNodo2, idNodo1, arcType,
301
							distance, cost);
302
					edgeCount++;
303

  
304
				}
305
				if (direction == 1) {
306
					sentidoDigit = 1; // En esa direcci?n
307
					writeEdge(i, sentidoDigit, idNodo1, idNodo2, arcType,
308
							distance, cost);
309
					edgeCount++;
310
				}
311
				if (direction == 2) {
312
					sentidoDigit = 0;
313
					writeEdge(i, sentidoDigit, idNodo2, idNodo1, arcType,
314
							distance, cost);
315
					edgeCount++;
316

  
317
				}
318

  
319
			}
320

  
321
			nodeWriter.postProcess();
322
			edgeWriter.postProcess();
323
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
324
			e.printStackTrace();
325
			throw new DriverException(e);
326
		} catch (DriverIOException e) {
327
			e.printStackTrace();
328
			throw new DriverException(e);
329
		}
330

  
331
	}
332

  
333
	private void writeNode(NodeGv node) throws EditionException {
334
		Value[] values = new Value[nodeFields.length];
335
		int id = node.getId().intValue();
336
		values[0] = ValueFactory.createValue(id);
337
		values[1] = ValueFactory.createValue(node.getCoordinate().x);
338
		values[2] = ValueFactory.createValue(node.getCoordinate().y);
339
		DefaultRow myRow = new DefaultRow(values, id + "");
340
		IRowEdited editedRow = new DefaultRowEdited(myRow,
341
				DefaultRowEdited.STATUS_ADDED, id);
342

  
343
		nodeWriter.process(editedRow);	
344
	}
345
	
346

  
347
	
348
	/**
349
	 * Writes .red file (IVER network format). Useful to do some tests.
350
	 * @param lyrSrc
351
	 * @param redFile
352
	 * @return
353
	 * @throws DriverException
354
	 * @throws IOException
355
	 */
356
	public int createRedFile(FLyrVect lyrSrc, File redFile,  CancellableMonitorable cancel)
357
			throws DriverException {
358
		// PRIMERO VAN EL NUMERO DE TRAMOS, LUEGO EL NUMERO DE ARCOS Y LUEGO
359
		// EL NUMERO DE NODOS, DESPUES
360
		// IDTRAMO-SENTIDO_DIGITALIZACION-IDNODOORIGEN-IDNODODESTINO-TIPOTRAMO-DISTANCIA
361
		// Y POR FIN
362
		// IDNODO-XLONG-YLONG
363

  
364
		// El campo sentido indica //3-> Doble sentido, 1-> seg?n viene, 2
365
		// -> al rev?s, cualquier otro valor-> No hay arco
366
		// TipoTamo va a ser un campo num?rico, entero.
367
		// 0-> Autopista.
368
		// 1-> Autov?a.
369
		// 2-> Nacional.
370
		// 3-> Nacional - Comarcal.
371
		// 4-> Comarcal.
372
		// 5-> Otras.
373
		// 6-> Ferry.
374
		// 7-> Conexiones
375
		// Los nombres son orientativos. Basta saber que puede haber hasta X
376
		// tipos distintos de tramos, cada uno
377
		// con su velocidad. Esa velocidad se fijar? en la funci?n
378
		// FijaVelocidades. OJO, empezar siempre desde el 0
379

  
380
		double distance, cost;
381
		short arcType;
382
		int direction;
383
		int i;
384
		int idNodo1, idNodo2, nodeCount, edgeCount;
385
		short sentidoDigit; // => 1 en esa direcci?n. 0=> Al contrario. SOLO
386
		// SE UTILIZA PARA LOS CALCULOS POR IDTRAMO Y
387
		// PORCENTAJE
388
		// PARA SABER SI EST? M?S CERCA DE UN NODO O DEL OTRO.
389

  
390
		Hashtable nodeHash = new Hashtable();
391
		ArrayList nodes = new ArrayList();
392

  
393
		try {
394
			if (lyrSrc.getShapeType() != FShape.LINE) {
395
				return -1;
396
			}
397
			RandomAccessFile file = new RandomAccessFile(redFile.getPath(),
398
					"rw");
399
			FileImageOutputStream output = new FileImageOutputStream(file);
400
//			FileChannel channel = file.getChannel();
401
//			MappedByteBuffer buf = channel.map(MapMode.READ_WRITE, 0,
402
//					16 * 1024);
403
//			buf.order(ByteOrder.LITTLE_ENDIAN);
404
			output.setByteOrder(ByteOrder.LITTLE_ENDIAN);
405

  
406
			nodeCount = 0;
407
			VectorialAdapter adapter = (VectorialAdapter) lyrSrc.getSource();
408
			int numTramos;
409

  
410
			numTramos = adapter.getShapeCount();
411
			// Cambiamos otra vez: Escribimos primero el n? de tramos. Luego va
412
			// el n? de arcos y el de nodos.
413
			// buf.putInt(numTramos);
414
			output.writeInt(numTramos);
415
			// /////// Cambiamos el formato: primero van los arcos y luego los
416
			// nodos
417
			// file.writeInt(0);
418
			output.writeInt(0);
419
			// OJO: El numero de arcos todav?a no lo sabemos, habr? que volver
420
			// luego y escribir el numero correcto. Es por lo de los sentidos.
421
			// Metemos 2 arcos si es doble sentido, y uno si es de un solo
422
			// sentido
423

  
424
			// Guardamos un long. Luego volveremos aqu? y grabaremos el n? de
425
			// nodos
426
			// file.writeInt(0);
427
			output.writeInt(numTramos);
428
			// AHORA METEMOS LOS NOMBRES DE LOS CAMPOS. EN EL CARGA RED LOS
429
			// USAREMOS PARA LEER DEL DBF.
430

  
431
			edgeCount = 0;
432

  
433
			SelectableDataSource sds = lyrSrc.getRecordset();
434
			int senseFieldIndex = -1;
435
			int distFieldIndex = -1;
436
			int typeFieldIndex = -1;
437
			int costFieldIndex = -1;
438
			
439
			if (fieldSense != null)
440
				senseFieldIndex = sds.getFieldIndexByName(fieldSense);
441
			if (fieldDist != null)
442
				distFieldIndex = sds.getFieldIndexByName(fieldDist);
443
			if (fieldType != null)
444
				typeFieldIndex = sds.getFieldIndexByName(fieldType);
445
			if (fieldCost != null)
446
				costFieldIndex = sds.getFieldIndexByName(fieldCost);
447

  
448
			NumericValue valAux = null;
449
			for (i = 0; i < numTramos; i++) {
450
				IGeometry geom = adapter.getShape(i);
451
				Geometry jtsGeom = geom.toJTSGeometry();
452
				Coordinate[] coords = jtsGeom.getCoordinates();
453
				Coordinate c1 = coords[0];
454
				Coordinate c2 = coords[coords.length - 1];
455
				
456
				if(cancel != null)
457
					cancel.reportStep();
458

  
459
				NodeGv nodeAux;
460
				if (!nodeHash.containsKey(c1)) // No est?.
461
				{
462
					idNodo1 = nodeCount++;
463
					nodeAux = new NodeGv(c1, idNodo1);
464
					nodeHash.put(c1, nodeAux);
465
					nodes.add(nodeAux);
466
				} else {
467
					nodeAux = (NodeGv) nodeHash.get(c1);
468
				}
469
				idNodo1 = nodeAux.getId().intValue();
470

  
471
				if (!nodeHash.containsKey(c2)) // No est?.
472
				{
473
					idNodo2 = nodeCount++;
474
					nodeAux = new NodeGv(c2, idNodo2);
475
					nodeHash.put(c2, nodeAux);
476
					nodes.add(nodeAux);
477

  
478
				} else {
479
					nodeAux = (NodeGv) nodeHash.get(c2);
480
				}
481
				idNodo2 = nodeAux.getId().intValue();
482

  
483
				if (typeFieldIndex != -1)
484
					valAux = (NumericValue) sds.getFieldValue(i, typeFieldIndex);
485
				else
486
					valAux = ValueFactory.createValue(0); // no hay tipo
487
				arcType = valAux.shortValue();
488
				// TipoTramo = DBFReadIntegerAttribute(hDBF, i, indiceCampo1);
489
				
490
				if (distFieldIndex != -1)
491
					valAux = (NumericValue) sds.getFieldValue(i, distFieldIndex);
492
				else
493
					valAux = ValueFactory.createValue(jtsGeom.getLength());
494
				distance = valAux.floatValue();
495
				// Distancia = (float) DBFReadDoubleAttribute(hDBF, i,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff