Revision 17896

View differences:

tags/tmp_build/extensions/extGraph/build.xml
1
<project name="Generar extension en Andami" default="generate-without-source" basedir=".">
2
    <description>
3
        Instala el plugin de ejemplo en Andami.
4
    </description>
5
  <!-- set global properties for this build -->
6
  <property name="src" location="src"/>
7
  <property name="build" location="bin"/>
8
  <property name="dist"  location="dist"/>
9
  <property name="plugin" value="com.iver.cit.gvsig.graph"/>
10
  <property name="plugin-fmap-gvsig" value="com.iver.cit.gvsig.graph-fmap-gvsig"/>
11
  <property name="extension-dir" location="../_fwAndami/gvSIG/extensiones"/>
12
  <property name="mainPlugin" value="com.iver.cit.gvsig" />
13
  <property name="fmapLibs"  location="../libFMap/lib"/>
14
  <import file="../binaries/ant/utilities.xml"/>
15
  <target name="init">
16
    <!-- Create the time stamp -->
17
    <tstamp/>
18
    <!-- Create the build directory structure used by compile -->
19
    <mkdir dir="${build}"/>
20
    <mkdir dir="${dist}"/>
21
    <mkdir dir="${dist}/lib"/>
22

  
23
    <!-- Creamos un fichero con el timeStamp para que lo lea el FPanelAbout -->
24
    <!--<buildnumber/>-->
25

  
26
  </target>
27

  
28
  <target name="compile" description="compile the source" >
29
		<antcall target="gvSIG-import-build-number"/>
30
		<!-- Compile the Java code from ${src} to ${build} -->
31
		<mkdir dir="${build}" />
32
		<loadEclipseClasspath project="${basedir}"/>
33
		<gvSIG-javac
34
			classpath="${eclipseClasspath}"
35
		/>
36
  </target>
37

  
38

  
39
  <target name="generate-jars">
40
    <jar jarfile="${dist}/lib/${plugin}.jar" basedir="${build}" includes="com/iver/cit/**"/>
41
  	<jar jarfile="${extension-dir}/${mainPlugin}/lib/${mainPlugin}.jar"
42
  			basedir="${build}"
43
  			includes="com/iver/cit/gvsig/project/documents/view/legend/gui/**"
44
  			update="yes" />
45

  
46
  </target>
47

  
48
  <target name="copy-data-files">
49
    <copy file="config/config.xml" todir="${dist}"/>
50
    <copy file="config/about.htm" todir="${dist}"/>
51
    <copy todir="${dist}">
52
      <fileset dir="config/" includes="text*.properties"/>
53
    </copy>
54
    <copy todir="${dist}/lib">
55
      <fileset dir="lib" includes="*"/>
56
    </copy>
57
    <copy todir="${dist}/images">
58
      <fileset dir="images/" includes="*"/>
59
    </copy>
60
    <copy todir="${dist}/symbols">
61
      <fileset dir="symbols/" includes="**/**"/>
62
    </copy>
63
  </target>
64

  
65
  <target name="copy-to-andami">
66
    <copy todir="${extension-dir}/${plugin}/">
67
      <!--<fileset dir="${dist}" includes="**/**"/>-->
68
      <fileset dir="${dist}">
69
      	<exclude name="**/${plugin-fmap-gvsig}.jar"/>
70
      	<include name="**/**"/>
71
	  </fileset>
72
    </copy>
73
  	<copy todir="${extension-dir}/${mainPlugin}/lib/">
74
  	  		<fileset dir="${dist}/lib" includes="**/${plugin-fmap-gvsig}.jar"/>
75
  	</copy>
76
 	<delete dir="${dist}"/>
77
  </target>
78

  
79
  <target name="batch-build"
80
	 depends="init,compile,generate-jars,copy-data-files,copy-to-andami"/>
81

  
82
  <target name="generate-without-source" description="generate the distribution without the source file"
83
	 depends="init,generate-jars,copy-data-files,copy-to-andami">
84
    <!-- Create the distribution directory -->
85

  
86
    <!--<jar jarfile="${fmapLibs}/jts-1.7.jar" basedir="${build}" update="yes" includes="com/vividsolutions/**"/>-->
87
    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
88
  	<!-- These files have been moved to FMap
89

  
90
    <jar jarfile="${dist}/lib/${plugin-fmap-gvsig}.jar" basedir="${build}" includes="com/iver/cit/fmap/**,com/iver/cit/gvsig/**,com/iver/cit/project/**"
91
     excludes="com/iver/cit/gvsig/project/documents/view/legend/gui/**" />
92
     -->
93

  
94

  
95
  <!--${extension-dir}/${mainPlugin}/lib/${mainPlugin}.jar	<copy todir="${fmapLibs}">
96
  		<fileset dir="${dist}/lib" includes="**/${plugin-fmap-gvsig}.jar"/>
97
  	</copy> -->
98

  
99
    </target>
100

  
101
    <target name="save-gvsig-jar-to-install-dir" description="Save the gvsig.jar to installdir" >
102
  	<!-- ******************************* -->
103

  
104
  	<copy todir="./install">
105
  		<fileset dir="${extension-dir}/com.iver.cit.gvsig/lib/">
106
  			<include name="com.iver.cit.gvsig.jar"/>
107
		</fileset>
108
  	</copy>
109
  	<!-- ******************************* -->
110

  
111
  </target>
112

  
113
	<target name="clean"
114
	        description="clean up" >
115
		<delete dir="${build}" failonerror="no"/>
116
		<delete dir="${dist}" failonerror="no"/>
117
	</target>
118
</project>
119

  
0 120

  
tags/tmp_build/extensions/extGraph/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="src" path="src-test"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6
	<classpathentry kind="src" path="/_fwAndami"/>
7
	<classpathentry kind="src" path="/libFMap"/>
8
	<classpathentry kind="src" path="/libIverUtiles"/>
9
	<classpathentry kind="src" path="/appgvSIG"/>
10
	<classpathentry kind="lib" path="lib/colt.jar"/>
11
	<classpathentry kind="lib" path="lib/commons-collections-3.2.jar"/>
12
	<classpathentry kind="lib" path="lib/jung-1.7.4.jar" sourcepath="/JUNG_1_7_4"/>
13
	<classpathentry kind="var" path="JUNIT_HOME/junit.jar" sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip"/>
14
	<classpathentry combineaccessrules="false" kind="src" path="/extGeoProcessing"/>
15
	<classpathentry kind="lib" path="/_fwAndami/lib/castor-0.9.5.3-xml.jar"/>
16
	<classpathentry combineaccessrules="false" kind="src" path="/extCAD"/>
17
	<classpathentry kind="lib" path="/libFMap/lib/driver-manager-1.1.jar" sourcepath="/libDriverManager"/>
18
	<classpathentry combineaccessrules="false" kind="src" path="/extGeoprocessingExtensions"/>
19
	<classpathentry combineaccessrules="false" kind="src" path="/extJCRS"/>
20
	<classpathentry kind="lib" path="/libFMap/lib/org.cresques.cts.jar"/>
21
	<classpathentry kind="lib" path="/libFMap/lib/gdbms-0.8-SNAPSHOT.jar" sourcepath="/libGDBMS"/>
22
	<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.ui.jar" sourcepath="/libUIComponent/src"/>
23
	<classpathentry kind="lib" path="/_fwAndami/lib/JWizardComponent.jar"/>
24
	<classpathentry kind="lib" path="/libFMap/lib/jts-1.8.jar"/>
25
	<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.exceptions.jar"/>
26
	<classpathentry kind="output" path="bin"/>
27
</classpath>
0 28

  
tags/tmp_build/extensions/extGraph/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>extGraph</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>de.loskutov.FileSync.FSBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
	</buildSpec>
19
	<natures>
20
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
21
		<nature>org.eclipse.jdt.core.javanature</nature>
22
		<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
23
	</natures>
24
</projectDescription>
0 25

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestNetworkRedWriter.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3

  
4
import java.io.File;
5

  
6
import junit.framework.TestCase;
7

  
8
import org.cresques.cts.IProjection;
9
import org.gvsig.exceptions.BaseException;
10

  
11
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
12
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
13
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
14
import com.iver.cit.gvsig.graph.core.writers.NetworkFileRedWriter;
15

  
16
public class TestNetworkRedWriter extends TestCase {
17
	NetworkFileRedWriter netBuilder = new NetworkFileRedWriter();
18
	FLyrVect lyr;
19
	File redFile;
20
	/*
21
	 * Test method for
22
	 * 'com.iver.cit.gvsig.graph.core.NetworkWriter.writeNetwork()'
23
	 */
24
	public void testWriteNetwork() {
25
		try {
26
			long t1 = System.currentTimeMillis();
27
			netBuilder.writeNetwork();
28
			long t2 = System.currentTimeMillis();
29
			System.out.println("Building RED time:" + (t2-t1) + " msecs.");
30
		} catch (BaseException e) {
31
			// TODO Auto-generated catch block
32
			e.printStackTrace();
33
		}
34
	}
35

  
36

  
37
	protected void setUp() throws Exception {
38
		LayerFactory
39
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
40
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
41
		File shpFile = new File("c:/ejes.shp");
42
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes",
43
				"gvSIG shp driver", shpFile, prj);
44

  
45
		String redFilePath = lyr.getName().replaceFirst("\\Q.shp\\E", "");
46
		redFile = new File("c:/" + redFilePath + ".red");
47
		
48
		redFile.delete();
49
		
50
		String fieldType = "tipored";
51
		String fieldDist = "length";
52
		String fieldCost = "cost";
53
		String fieldSense = "";
54

  
55
		netBuilder.setLayer(lyr);
56
		netBuilder.setFieldCost(fieldCost);
57
		netBuilder.setFieldType(fieldType);
58
		netBuilder.setFieldDist(fieldDist);
59
		netBuilder.setFieldSense(fieldSense);
60
		
61
		netBuilder.setRedFile(redFile);
62
		
63
		
64
		
65
	}
66

  
67
}
0 68

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestServiceAreaPolygon.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

  
42

  
43
package com.iver.cit.gvsig.graphtests;
44

  
45
import java.io.File;
46

  
47
import junit.framework.TestCase;
48

  
49
import org.cresques.cts.IProjection;
50
import org.gvsig.exceptions.BaseException;
51

  
52
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
53
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
54
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
55
import com.iver.cit.gvsig.graph.core.GvFlag;
56
import com.iver.cit.gvsig.graph.core.IGraph;
57
import com.iver.cit.gvsig.graph.core.Network;
58
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
59
import com.iver.cit.gvsig.graph.solvers.OneToManySolver;
60
import com.iver.cit.gvsig.graph.solvers.ServiceAreaExtractor2;
61

  
62
/**
63
 * @author fjp
64
 *
65
 * A partir de un iterador de Features (de l?neas), implementamos probamos que
66
 * podemos generar un pol?gono (si puede ser, convexo) que las
67
 * englobe todas. 
68
 */
69
public class TestServiceAreaPolygon extends TestCase {
70

  
71
	FLyrVect lyr;
72
	Network net;
73
	IGraph g;
74

  
75

  
76
	protected void setUp() throws Exception {
77
		super.setUp();
78
		// Setup de los drivers
79
		LayerFactory
80
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
81

  
82
		// Setup del factory de DataSources
83

  
84
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
85
		File shpFile = new File("test_files/ejes.shp");
86
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver",
87
				shpFile, prj);
88
		
89
		NetworkRedLoader netLoader = new NetworkRedLoader();
90
		netLoader.setNetFile(new File("test_files/ejes.net"));
91
		g = netLoader.loadNetwork();
92
		
93
		net = new Network();
94
	}
95

  
96
	public void testCalculate() throws BaseException {
97
		OneToManySolver solver = new OneToManySolver();
98
		net.setLayer(lyr);
99
		net.setGraph(g);
100
		solver.setNetwork(net);
101
		
102
		ServiceAreaExtractor2 extractor = new ServiceAreaExtractor2(net);
103
		solver.addListener(extractor);
104
		
105
		//		 Source flag
106
		GvFlag sourceFlag = net.createFlag(441901, 4475977, 10);
107
		extractor.setIdFlag(0);
108
		net.addFlag(sourceFlag);
109
		solver.setSourceFlag(sourceFlag);
110

  
111
		//		 Destination flags
112
		// NONE: We will use dijkstra algorithm to label network
113
		// and extract (after) the visited arcs.
114
//		net.addFlag(441901, 4475977, 10);
115
//		net.addFlag(442830, 4476201, 200);
116
//		net.addFlag(442673, 4475125, 200);
117
		long t1 = System.currentTimeMillis();
118
		solver.putDestinationsOnNetwork();
119
		solver.setExploreAllNetwork(true);
120
		solver.setMaxDistance(4000.0);
121
		solver.calculate();
122
		solver.removeDestinationsFromNetwork();
123
		double[] costs = {1000.0, 3000.0};
124
		extractor.setCosts(costs);
125
		extractor.writeServiceArea();
126
		extractor.closeFiles();
127
		
128
		long t2 = System.currentTimeMillis();
129
		System.out.println("tiempo:" + (t2-t1));
130
		
131
		// assertEquals(dist.doubleValue(), 8887, 0);
132

  
133
		
134
		
135

  
136

  
137
	}
138

  
139
}
0 140

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestAngle.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.graphtests;
42

  
43
import com.iver.cit.gvsig.graph.core.TurnUtil;
44
import com.vividsolutions.jts.algorithm.CGAlgorithms;
45
import com.vividsolutions.jts.geom.Coordinate;
46
import com.vividsolutions.jts.geom.LineSegment;
47

  
48
import junit.framework.TestCase;
49

  
50
public class TestAngle extends TestCase {
51
	
52
	public void testAngle() {
53
		Coordinate c1, c2, c3;
54
		double grados;
55
		
56
		// 0 grados (no hay giro
57
		c1 = new Coordinate(-1, 0);
58
		c2 = new Coordinate(0, 0);
59
		c3 = new Coordinate(1, 0);
60
		grados = TurnUtil.angle(c1, c2, c3);
61
		assertEquals(0.0, grados, 0.0);
62
		
63
		
64
		// 90 grados (giro a la izquierda)
65
		c1 = new Coordinate(0, -1);
66
		c2 = new Coordinate(0, 0);
67
		c3 = new Coordinate(-1, 0);
68
		grados = TurnUtil.angle(c1, c2, c3);
69
		assertEquals(90.0, grados, 0.0);
70

  
71
		
72
		// 180 grados (360 grados) giro completo
73
		c1 = new Coordinate(-1, 0);
74
		c2 = new Coordinate(0, 0);
75
		c3 = new Coordinate(-1, 0);
76
		grados = TurnUtil.angle(c1, c2, c3);
77
		assertEquals(180.0, grados, 0.0);
78
		
79
		// 270 grados (giro a la derecha)
80
		c1 = new Coordinate(-1, 0);
81
		c2 = new Coordinate(0, 0);
82
		c3 = new Coordinate(0, 1);
83
		grados = TurnUtil.angle(c1, c2, c3);
84
		assertEquals(270.0, grados, 0.0);
85
		
86
	}
87
	
88
	private double angle(Coordinate c1, Coordinate c2, Coordinate c3) {
89
		double resul = 0.0;
90
		// Normalizamos:
91
		Coordinate origin = new Coordinate(0.0, 0.0);
92
		Coordinate cAux1 = new Coordinate(c2.x-c1.x, c2.y-c1.y);
93
		Coordinate cAux2 = new Coordinate(c3.x-c2.x, c3.y-c2.y);
94
		LineSegment v1 = new LineSegment(origin, cAux1);
95
		LineSegment v2 = new LineSegment(origin, cAux2);
96
		double jtsResul = CGAlgorithms.orientationIndex(c1, c2, c3);
97
		double prodEscalar = cAux1.x*cAux2.x + cAux1.y*cAux2.y;
98
		double cosAlpha = prodEscalar / (v1.getLength() * v2.getLength()) ; 
99
		resul = Math.toDegrees(Math.acos(cosAlpha));
100
		
101
        if (cAux1.x * cAux2.y > cAux1.y * cAux2.x) {
102
            resul = 360 - resul;
103
        }
104

  
105
		System.out.println(resul);
106
		return resul;
107
	}
108

  
109
}
110

  
111

  
0 112

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestLoader.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3

  
4
import java.io.File;
5

  
6
import junit.framework.TestCase;
7

  
8
import org.cresques.cts.IProjection;
9
import org.gvsig.exceptions.BaseException;
10

  
11
import com.hardcode.gdbms.engine.data.DataSource;
12
import com.hardcode.gdbms.engine.data.DataSourceFactory;
13
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
14
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
15
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
16
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
17
import com.iver.cit.gvsig.graph.core.EdgeWeightLabeller;
18
import com.iver.cit.gvsig.graph.core.FNode;
19
import com.iver.cit.gvsig.graph.core.GraphException;
20
import com.iver.cit.gvsig.graph.core.IGraph;
21
import com.iver.cit.gvsig.graph.core.JungGraph;
22
import com.iver.cit.gvsig.graph.core.Network;
23
import com.iver.cit.gvsig.graph.core.loaders.NetworkLoader;
24
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
25
import com.iver.cit.gvsig.graph.solvers.Route;
26
import com.iver.cit.gvsig.graph.solvers.ShortestPathSolverAStar;
27
import com.iver.cit.gvsig.graph.solvers.ShortestPathSolverDijkstra;
28

  
29
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance;
30
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
31
import edu.uci.ics.jung.graph.ArchetypeVertex;
32
import edu.uci.ics.jung.graph.Graph;
33

  
34
public class TestLoader extends TestCase {
35
	DataSourceFactory dsf;
36

  
37
	FLyrVect lyr;
38

  
39
	public void testLoadRedNetwork() {
40
		NetworkRedLoader netLoader = new NetworkRedLoader();
41
		IGraph g = netLoader.loadNetwork();
42

  
43
		// Probamos la algoritmia: distancia entre nodo 1 y nodo 1000
44
		Network net = new Network();
45
		ShortestPathSolverDijkstra solver = new ShortestPathSolverDijkstra();
46
		net.setLayer(lyr);
47
		net.setGraph(g);
48
		solver.setNetwork(net);
49
		
50
		ShortestPathSolverAStar solverAstar = new ShortestPathSolverAStar();
51
		solverAstar.setNetwork(net);
52
		
53
		try {
54

  
55
			// Primer punto
56
			net.addFlag(433647.09370, 4488029, 10);
57

  
58
			// Segundo punto
59
			net.addFlag(437290.96875, 4481547, 10);
60
			long t1 = System.currentTimeMillis();
61
			Route resul;
62
			solver.setFielStreetName("Nombre");
63
			resul = solver.calculateRoute();
64
			long t2 = System.currentTimeMillis();
65

  
66
			// assertEquals(dist.doubleValue(), 8887, 0);
67

  
68
			System.out.println("fjp dist =" + resul.getLength()
69
					+ " meters. msecs: " + (t2 - t1));
70

  
71
			t1 = System.currentTimeMillis();
72
			Route resul2;
73
			solverAstar.setFielStreetName("Nombre");
74
			resul2 = solverAstar.calculateRoute();
75
			t2 = System.currentTimeMillis();
76

  
77
			System.out.println("ASTAR dist =" + resul2.getLength()
78
					+ " meters. msecs: " + (t2 - t1));
79
			
80
			assertEquals(resul.getLength(), resul2.getLength(), 0.0);
81
			
82
			JungGraph jG = new JungGraph(g);
83
			// Probamos la algoritmia: distancia entre nodo 1 y nodo 1000
84
			DijkstraShortestPath distCalculator = new DijkstraShortestPath(jG,
85
					new EdgeWeightLabeller());
86
			FNode vOrig = jG.getVertexByID(1);
87
			FNode vEnd = jG.getVertexByID(1000);
88
			t1 = System.currentTimeMillis();
89
			Number dist = distCalculator.getDistance(vOrig, vEnd);
90
			t2 = System.currentTimeMillis();
91

  
92
			// assertEquals(dist.doubleValue(), 8887, 0);
93

  
94
			System.out
95
					.println("dist =" + dist + " meters. msecs: " + (t2 - t1));
96

  
97
			System.out.println(vOrig + " - " + vEnd);
98
			System.out.println(vOrig.getX() + ", " + vOrig.getY() + " - "
99
					+ vEnd.getX() + ", " + vEnd.getY());
100
			
101
			assertEquals(resul.getLength(), dist.doubleValue(), 0.4);
102

  
103
		} catch (GraphException e) {
104
			// TODO Auto-generated catch block
105
			e.printStackTrace();
106
		}
107

  
108
	}
109

  
110
	/*
111
	 * Test method for
112
	 * 'com.iver.cit.gvsig.graph.core.NetworkLoader.loadNetwork()'
113
	 */
114
	public void testLoadNetwork() {
115
		// if (true) return;
116
		NetworkLoader netLoader = new NetworkLoader(true);
117

  
118
		DataSource dsNodes;
119
		try {
120
			dsNodes = dsf.createRandomDataSource("nodes",
121
					DataSourceFactory.MANUAL_OPENING);
122

  
123
			DataSource dsEdges = dsf.createRandomDataSource("edges",
124
					DataSourceFactory.MANUAL_OPENING);
125

  
126
			SelectableDataSource sdsNodes = new SelectableDataSource(dsNodes);
127
			SelectableDataSource sdsEdges = new SelectableDataSource(dsEdges);
128

  
129
			netLoader.setNodeReader(sdsNodes);
130
			netLoader.setEdgeReader(sdsEdges);
131

  
132
			Graph g = netLoader.loadJungNetwork();
133

  
134
			System.out.println("Num nodos=" + g.numVertices() + " numEdges = "
135
					+ g.numEdges());
136

  
137
			// Probamos la algoritmia: distancia entre nodo 1 y nodo 1000
138
			DijkstraDistance distCalculator = new DijkstraDistance(g,
139
					new EdgeWeightLabeller());
140
			ArchetypeVertex vOrig = netLoader.getIndexer().getVertex(1);
141
			ArchetypeVertex vEnd = netLoader.getIndexer().getVertex(1000);
142
			long t1 = System.currentTimeMillis();
143
			Number dist = distCalculator.getDistance(vOrig, vEnd);
144
			long t2 = System.currentTimeMillis();
145

  
146
			// assertEquals(dist.doubleValue(), 8887, 0);
147

  
148
			System.out
149
					.println("dist =" + dist + " meters. msecs: " + (t2 - t1));
150
			System.out.println(vOrig + " - " + vEnd);
151
			System.out.println(vOrig.getUserDatum("X") + ", "
152
					+ vOrig.getUserDatum("Y") + " - " + vEnd.getUserDatum("X")
153
					+ ", " + vEnd.getUserDatum("Y"));
154

  
155
		} catch (BaseException e) {
156
			// TODO Auto-generated catch block
157
			e.printStackTrace();
158
		}
159

  
160
	}
161

  
162
	protected void setUp() throws Exception {
163
		// Setup de los drivers
164
		LayerFactory
165
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
166

  
167
		// Setup del factory de DataSources
168
		dsf = LayerFactory.getDataSourceFactory();
169

  
170
		// Setup de las tablas
171
		dsf.addFileDataSource("gdbms dbf driver", "nodes", "c:/nodes.dbf");
172
		dsf.addFileDataSource("gdbms dbf driver", "edges", "c:/edges.dbf");
173

  
174
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
175
		File shpFile = new File("c:/ejes.shp");
176
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver",
177
				shpFile, prj);
178

  
179
	}
180

  
181
	protected void tearDown() throws Exception {
182
		// TODO Auto-generated method stub
183
		super.tearDown();
184
	}
185

  
186
}
0 187

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestClosestFacilty.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3
import java.io.File;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.cresques.cts.IProjection;
8
import org.gvsig.exceptions.BaseException;
9

  
10
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
11
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
12
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
13
import com.iver.cit.gvsig.graph.core.GvFlag;
14
import com.iver.cit.gvsig.graph.core.IGraph;
15
import com.iver.cit.gvsig.graph.core.Network;
16
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
17
import com.iver.cit.gvsig.graph.solvers.OneToManySolver;
18
import com.iver.cit.gvsig.graph.solvers.Route;
19
import com.iver.cit.gvsig.graph.solvers.ShortestPathSolverAStar;
20

  
21
public class TestClosestFacilty extends TestCase {
22
	FLyrVect lyr;
23
	Network net;
24
	IGraph g;
25
	
26
	protected void setUp() throws Exception {
27
		super.setUp();
28
		// Setup de los drivers
29
		LayerFactory
30
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
31

  
32
		// Setup del factory de DataSources
33

  
34
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
35
		File shpFile = new File("test_files/ejes.shp");
36
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver",
37
				shpFile, prj);
38
		
39
		NetworkRedLoader netLoader = new NetworkRedLoader();
40
		netLoader.setNetFile(new File("test_files/ejes.net"));
41
		g = netLoader.loadNetwork();
42
		
43
		net = new Network();
44
	}
45
	
46
	public void testCalculate() throws BaseException {
47
		OneToManySolver solver = new OneToManySolver();
48
		net.setLayer(lyr);
49
		net.setGraph(g);
50
		solver.setNetwork(net);
51
		
52
		//		 Source flag
53
		GvFlag sourceFlag = net.createFlag(442177.19, 4476236.12, 10);
54
		net.addFlag(sourceFlag);
55
		solver.setSourceFlag(sourceFlag);
56
		
57
		GvFlag[] facilitiesFlags={
58
				net.createFlag(442211.67, 4476093.92, 10),
59
				net.createFlag(441703.18, 4475266.55, 10),
60
				net.createFlag(441022.33, 4476843.72, 10),
61
				net.createFlag(442612.42, 4476744.61, 10)
62
		};
63
		
64
		//		 Destination flags
65
		// NONE: We will use dijkstra algorithm to label network
66
		// and extract (after) the visited arcs.
67
		for (int i = 0; i < facilitiesFlags.length; i++) {
68
			net.addFlag(facilitiesFlags[i]);
69
		}
70

  
71
		long t1 = System.currentTimeMillis();
72
		solver.putDestinationsOnNetwork();
73
		solver.setExploreAllNetwork(false);
74
		solver.setMaxCost(4000.0);
75
		solver.calculate();
76
		solver.removeDestinationsFromNetwork();
77
		
78
		// En este punto tenemos la red "etiquetada" con los pesos
79
		// y distancias. Hay 2 opciones: recorrer toda la capa
80
		// y copiar los registros que nos interesan (opci?n f?cil)
81
		// o implementar un listener que vaya vigilando los
82
		// arcos que se est?n evaluando dentro del algoritmo de
83
		// dijkstra.
84
		// Primero opci?n f?cil
85
		// Recorremos la capa, vemos en qu? intervalo cae cada
86
		// entidad y escribimos un shape.
87
		
88
		GvFlag[] flags=net.getFlags();
89
		GvFlag closestFlag=null;
90
		if(flags.length>1){
91
			closestFlag=flags[1];
92
			
93
			for(int i=1;i<flags.length;i++){
94
				if(flags[i].getCost()<closestFlag.getCost()) closestFlag=flags[i];
95
			}
96
			
97
			System.out.println("Hacia el Proveedor:\nProveedor m?s cercano: "+closestFlag.getIdFlag()+" ("+closestFlag.getCost()+")");
98
		}
99
		else {
100
			System.out.println("Sin proveedores");
101
		}
102
		
103
		long t2 = System.currentTimeMillis();
104
		System.out.println("tiempo:" + (t2-t1));
105
		
106
		
107
		//Desde el proveedor
108
		try {
109
			this.setUp();
110
		} catch (Exception e) {
111
			// TODO Auto-generated catch block
112
			e.printStackTrace();
113
		}
114
		
115
		ShortestPathSolverAStar solverFromFacility=new ShortestPathSolverAStar();
116
		net.setLayer(lyr);
117
		net.setGraph(g);
118
		solverFromFacility.setNetwork(net);
119
		
120
		GvFlag destinyFlag = sourceFlag; //Ahora el punto de origen pasa a ser el destino
121
		
122
		Route bestRoute=null;
123
		GvFlag closestFacility=null;
124
		long ini=System.currentTimeMillis();
125
		for (int i = 0; i < facilitiesFlags.length; i++) {
126
			net.removeFlags();
127
			net.addFlag(facilitiesFlags[i]);
128
			net.addFlag(destinyFlag);
129
			Route route=solverFromFacility.calculateRoute();
130
			if(bestRoute==null || route.getCost()<bestRoute.getCost()){
131
				bestRoute=route;
132
				closestFacility=facilitiesFlags[i];
133
			}
134
		}
135
		long time=System.currentTimeMillis()-ini;
136
		
137
		System.out.println("Desde el proveedor: ");
138
		System.out.println("El mejor proveedor es: "+closestFacility.getIdFlag()+" ("+bestRoute.getCost()+")");
139
		
140
		System.out.println("Coste: "+time);
141
		
142
		
143
		// assertEquals(dist.doubleValue(), 8887, 0);
144
	}
145
}
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestOneToMany.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3
import java.io.File;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.cresques.cts.IProjection;
8

  
9
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
10
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
11
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
12
import com.iver.cit.gvsig.graph.core.GraphException;
13
import com.iver.cit.gvsig.graph.core.GvFlag;
14
import com.iver.cit.gvsig.graph.core.IGraph;
15
import com.iver.cit.gvsig.graph.core.Network;
16
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
17
import com.iver.cit.gvsig.graph.solvers.OneToManySolver;
18

  
19
public class TestOneToMany extends TestCase {
20

  
21
	FLyrVect lyr;
22
	Network net;
23
	IGraph g;
24

  
25

  
26
	protected void setUp() throws Exception {
27
		super.setUp();
28
		// Setup de los drivers
29
		LayerFactory
30
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
31

  
32
		// Setup del factory de DataSources
33

  
34
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
35
		File shpFile = new File("test_files/ejes.shp");
36
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver",
37
				shpFile, prj);
38
		
39
		NetworkRedLoader netLoader = new NetworkRedLoader();
40
		netLoader.setNetFile(new File("test_files/ejes.net"));
41
		g = netLoader.loadNetwork();
42
		
43
		net = new Network();
44
		
45
		
46
		
47
		
48
		
49
		
50
		
51
	}
52

  
53
	public void testCalculate() throws GraphException {
54
		OneToManySolver solver = new OneToManySolver();
55
		net.setLayer(lyr);
56
		net.setGraph(g);
57
		solver.setNetwork(net);
58
		
59
		//		 Source flag
60
		GvFlag sourceFlag = net.createFlag(441901, 4475977, 10);
61
		solver.setSourceFlag(sourceFlag);
62

  
63
		//		 Destination flags
64
		net.addFlag(441901, 4475977, 10);
65
		net.addFlag(442830, 4476201, 200);
66
		net.addFlag(442673, 4475125, 200);
67
		long t1 = System.currentTimeMillis();
68
		solver.putDestinationsOnNetwork();
69
		solver.calculate();
70
		solver.removeDestinationsFromNetwork();
71
		long t2 = System.currentTimeMillis();
72
		System.out.println("tiempo:" + (t2-t1));
73
		
74
		GvFlag flags[] = net.getFlags();
75

  
76
		for (int i=0; i < flags.length; i++)
77
		{
78
			System.out.println("Flag " + i + " " + flags[i].getCost());
79
		}
80
		// assertEquals(dist.doubleValue(), 8887, 0);
81

  
82
		
83
		
84

  
85

  
86
	}
87

  
88
}
0 89

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestServiceArea.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

  
42
package com.iver.cit.gvsig.graphtests;
43

  
44
import java.io.File;
45

  
46
import junit.framework.TestCase;
47

  
48
import org.cresques.cts.IProjection;
49
import org.gvsig.exceptions.BaseException;
50

  
51
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
52
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
53
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
54
import com.iver.cit.gvsig.graph.core.GvFlag;
55
import com.iver.cit.gvsig.graph.core.IGraph;
56
import com.iver.cit.gvsig.graph.core.Network;
57
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
58
import com.iver.cit.gvsig.graph.solvers.OneToManySolver;
59
import com.iver.cit.gvsig.graph.solvers.ServiceAreaExtractor;
60

  
61
public class TestServiceArea extends TestCase {
62

  
63
	FLyrVect lyr;
64
	Network net;
65
	IGraph g;
66

  
67

  
68
	protected void setUp() throws Exception {
69
		super.setUp();
70
		// Setup de los drivers
71
		LayerFactory
72
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
73

  
74
		// Setup del factory de DataSources
75

  
76
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
77
		File shpFile = new File("test_files/ejes.shp");
78
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver",
79
				shpFile, prj);
80
		
81
		NetworkRedLoader netLoader = new NetworkRedLoader();
82
		netLoader.setNetFile(new File("test_files/ejes.net"));
83
		g = netLoader.loadNetwork();
84
		
85
		net = new Network();
86
	}
87

  
88
	public void testCalculate() throws BaseException {
89
		OneToManySolver solver = new OneToManySolver();
90
		net.setLayer(lyr);
91
		net.setGraph(g);
92
		solver.setNetwork(net);
93
		
94
		ServiceAreaExtractor extractor = new ServiceAreaExtractor(net);
95
		
96
		//		 Source flag
97
		GvFlag sourceFlag = net.createFlag(441901, 4475977, 10);
98
		net.addFlag(sourceFlag);
99
		solver.setSourceFlag(sourceFlag);
100

  
101
		//		 Destination flags
102
		// NONE: We will use dijkstra algorithm to label network
103
		// and extract (after) the visited arcs.
104
//		net.addFlag(441901, 4475977, 10);
105
//		net.addFlag(442830, 4476201, 200);
106
//		net.addFlag(442673, 4475125, 200);
107
		long t1 = System.currentTimeMillis();
108
		solver.putDestinationsOnNetwork();
109
		solver.setExploreAllNetwork(true);
110
		solver.setMaxDistance(4000.0);
111
		solver.calculate();
112
		solver.removeDestinationsFromNetwork();
113
		
114
		// En este punto tenemos la red "etiquetada" con los pesos
115
		// y distancias. Hay 2 opciones: recorrer toda la capa
116
		// y copiar los registros que nos interesan (opci?n f?cil)
117
		// o implementar un listener que vaya vigilando los
118
		// arcos que se est?n evaluando dentro del algoritmo de
119
		// dijkstra.
120
		// Primero opci?n f?cil
121
		// Recorremos la capa, vemos en qu? intervalo cae cada
122
		// entidad y escribimos un shape.
123
		double[] costs = {1000.0, 2000.0, 4000.0};
124
		extractor.doExtract(0, costs); // 2000 en unidades de coste. Normalmente ser?n segundos
125
		// TODO: Tambi?n puede ser interesante fijar un l?mite en distancia, no
126
		// en tiempo
127
		
128
		
129
		long t2 = System.currentTimeMillis();
130
		System.out.println("tiempo:" + (t2-t1));
131
		
132
		// assertEquals(dist.doubleValue(), 8887, 0);
133

  
134
		
135
		
136

  
137

  
138
	}
139

  
140
}
0 141

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/AllTests.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3

  
4
import junit.framework.Test;
5
import junit.framework.TestSuite;
6

  
7
public class AllTests {
8

  
9
	public static Test suite() {
10
		TestSuite suite = new TestSuite(
11
				"Test for com.iver.cit.gvsig.graph.test");
12
		//$JUnit-BEGIN$
13
		suite.addTestSuite(TestLoader.class);
14
		suite.addTestSuite(TestAngle.class);
15
		//$JUnit-END$
16
		return suite;
17
	}
18

  
19
}
20

  
21

  
0 22

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestNetworkGvTableWriter.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3

  
4
import java.io.File;
5

  
6
import junit.framework.TestCase;
7

  
8
import org.cresques.cts.IProjection;
9
import org.gvsig.exceptions.BaseException;
10

  
11
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
12
import com.iver.cit.gvsig.fmap.edition.writers.dbf.DbfWriter;
13
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
14
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
15
import com.iver.cit.gvsig.graph.core.writers.NetworkGvTableWriter;
16

  
17
public class TestNetworkGvTableWriter extends TestCase {
18
	NetworkGvTableWriter netBuilder = new NetworkGvTableWriter();
19
	FLyrVect lyr;
20
	/*
21
	 * Test method for
22
	 * 'com.iver.cit.gvsig.graph.core.NetworkWriter.writeNetwork()'
23
	 */
24
	public void testWriteNetwork() {
25
		try {
26
			long t1 = System.currentTimeMillis();
27
			netBuilder.writeNetwork();
28
			long t2 = System.currentTimeMillis();
29
			System.out.println("Building DBF time:" + (t2-t1) + " msecs.");
30
		} catch (BaseException e) {
31
			// TODO Auto-generated catch block
32
			e.printStackTrace();
33
		}
34
	}
35

  
36

  
37
	protected void setUp() throws Exception {
38
		LayerFactory
39
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
40
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
41
		File shpFile = new File("c:/ejes.shp");
42
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes",
43
				"gvSIG shp driver", shpFile, prj);
44

  
45
		String fieldType = "tipored";
46
		String fieldDist = "length";
47
		String fieldCost = "cost";
48
		String fieldSense = "";
49

  
50
		netBuilder.setLayer(lyr);
51
		netBuilder.setFieldCost(fieldCost);
52
		netBuilder.setFieldType(fieldType);
53
		netBuilder.setFieldDist(fieldDist);
54
		netBuilder.setFieldSense(fieldSense);
55
		DbfWriter nodeWriter = new DbfWriter();
56
		File nodeFile = new File("c:/nodes.dbf");
57
		nodeFile.delete();
58
		nodeWriter.setFile(nodeFile);
59

  
60
		File edgeFile = new File("c:/edges.dbf");
61
		DbfWriter edgeWriter = new DbfWriter();
62
		edgeWriter.setFile(edgeFile);
63
		
64
		
65
		netBuilder.setEdgeWriter(edgeWriter);
66
		netBuilder.setNodeWriter(nodeWriter);
67
		
68
		
69
		
70
	}
71

  
72
}
0 73

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestServiceArea2.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

  
42
package com.iver.cit.gvsig.graphtests;
43

  
44
import java.io.File;
45

  
46
import junit.framework.TestCase;
47

  
48
import org.cresques.cts.IProjection;
49
import org.gvsig.exceptions.BaseException;
50

  
51
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
52
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
53
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
54
import com.iver.cit.gvsig.graph.core.GvFlag;
55
import com.iver.cit.gvsig.graph.core.IGraph;
56
import com.iver.cit.gvsig.graph.core.Network;
57
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader;
58
import com.iver.cit.gvsig.graph.solvers.OneToManySolver;
59
import com.iver.cit.gvsig.graph.solvers.ServiceAreaExtractor2;
60

  
61
public class TestServiceArea2 extends TestCase {
62

  
63
	FLyrVect lyr;
64
	Network net;
65
	IGraph g;
66

  
67

  
68
	protected void setUp() throws Exception {
69
		super.setUp();
70
		// Setup de los drivers
71
		LayerFactory
72
				.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
73

  
74
		// Setup del factory de DataSources
75

  
76
		IProjection prj = CRSFactory.getCRS("EPSG:23030");
77
		File shpFile = new File("test_files/ejes.shp");
78
		lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver",
79
				shpFile, prj);
80
		
81
		NetworkRedLoader netLoader = new NetworkRedLoader();
82
		netLoader.setNetFile(new File("test_files/ejes.net"));
83
		g = netLoader.loadNetwork();
84
		
85
		net = new Network();
86
	}
87

  
88
	public void testCalculate() throws BaseException {
89
		OneToManySolver solver = new OneToManySolver();
90
		net.setLayer(lyr);
91
		net.setGraph(g);
92
		solver.setNetwork(net);
93
		
94
		ServiceAreaExtractor2 extractor = new ServiceAreaExtractor2(net);
95
		
96
		//		 Source flag
97
		GvFlag sourceFlag = net.createFlag(441901, 4475977, 10);
98
		net.addFlag(sourceFlag);
99
		solver.setSourceFlag(sourceFlag);
100
		solver.addListener(extractor);
101

  
102
		//		 Destination flags
103
		// NONE: We will use dijkstra algorithm to label network
104
		// and extract (after) the visited arcs.
105
//		net.addFlag(441901, 4475977, 10);
106
//		net.addFlag(442830, 4476201, 200);
107
//		net.addFlag(442673, 4475125, 200);
108
		extractor.setIdFlag(0);
109
		long t1 = System.currentTimeMillis();
110
		solver.putDestinationsOnNetwork();
111
		solver.setExploreAllNetwork(true);
112
		solver.setMaxDistance(4000.0);
113
		double[] costs = {1000.0, 2000.0}; 		
114
		extractor.setCosts(costs);
115
		
116
		solver.calculate();
117
		
118
		
119
		// En este punto tenemos la red "etiquetada" con los pesos
120
		// y distancias. Hay 2 opciones: recorrer toda la capa
121
		// y copiar los registros que nos interesan (opci?n f?cil)
122
		// o implementar un listener que vaya vigilando los
123
		// arcos que se est?n evaluando dentro del algoritmo de
124
		// dijkstra.
125
		// Primero opci?n f?cil
126
		// Recorremos la capa, vemos en qu? intervalo cae cada
127
		// entidad y escribimos un shape.
128
		extractor.closeFiles(); // 2000 en unidades de coste. Normalmente ser?n segundos
129
		solver.removeDestinationsFromNetwork();
130
		// TODO: Tambi?n puede ser interesante fijar un l?mite en distancia, no
131
		// en tiempo
132
		
133
		
134
		long t2 = System.currentTimeMillis();
135
		System.out.println("tiempo:" + (t2-t1));
136
		
137
		// assertEquals(dist.doubleValue(), 8887, 0);
138

  
139
		
140
		
141

  
142

  
143
	}
144

  
145
}
0 146

  
tags/tmp_build/extensions/extGraph/src-test/com/iver/cit/gvsig/graphtests/TestNetworJdbcWriter.java
1
package com.iver.cit.gvsig.graphtests;
2

  
3

  
4
import java.io.File;
5
import java.sql.Connection;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff