Revision 13850
trunk/extensions/extGraph_predes/src-test/com/iver/cit/gvsig/graphtests/TestServiceArea.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.ServiceAreaExtractor; |
|
19 |
|
|
20 |
public class TestServiceArea extends TestCase { |
|
21 |
|
|
22 |
FLyrVect lyr; |
|
23 |
Network net; |
|
24 |
IGraph g; |
|
25 |
|
|
26 |
|
|
27 |
protected void setUp() throws Exception { |
|
28 |
super.setUp(); |
|
29 |
// Setup de los drivers |
|
30 |
LayerFactory |
|
31 |
.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"); |
|
32 |
|
|
33 |
// Setup del factory de DataSources |
|
34 |
|
|
35 |
IProjection prj = CRSFactory.getCRS("EPSG:23030"); |
|
36 |
File shpFile = new File("test_files/ejes.shp"); |
|
37 |
lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver", |
|
38 |
shpFile, prj); |
|
39 |
|
|
40 |
NetworkRedLoader netLoader = new NetworkRedLoader(); |
|
41 |
netLoader.setNetFile(new File("test_files/ejes.net")); |
|
42 |
g = netLoader.loadNetwork(); |
|
43 |
|
|
44 |
net = new Network(); |
|
45 |
} |
|
46 |
|
|
47 |
public void testCalculate() throws BaseException { |
|
48 |
OneToManySolver solver = new OneToManySolver(); |
|
49 |
net.setLayer(lyr); |
|
50 |
net.setGraph(g); |
|
51 |
solver.setNetwork(net); |
|
52 |
|
|
53 |
ServiceAreaExtractor extractor = new ServiceAreaExtractor(net); |
|
54 |
|
|
55 |
// Source flag |
|
56 |
GvFlag sourceFlag = net.createFlag(441901, 4475977, 10); |
|
57 |
net.addFlag(sourceFlag); |
|
58 |
solver.setSourceFlag(sourceFlag); |
|
59 |
|
|
60 |
// Destination flags |
|
61 |
// NONE: We will use dijkstra algorithm to label network |
|
62 |
// and extract (after) the visited arcs. |
|
63 |
// net.addFlag(441901, 4475977, 10); |
|
64 |
// net.addFlag(442830, 4476201, 200); |
|
65 |
// net.addFlag(442673, 4475125, 200); |
|
66 |
long t1 = System.currentTimeMillis(); |
|
67 |
solver.putDestinationsOnNetwork(); |
|
68 |
solver.setExploreAllNetwork(true); |
|
69 |
solver.setMaxDistance(4000.0); |
|
70 |
solver.calculate(); |
|
71 |
solver.removeDestinationsFromNetwork(); |
|
72 |
|
|
73 |
// En este punto tenemos la red "etiquetada" con los pesos |
|
74 |
// y distancias. Hay 2 opciones: recorrer toda la capa |
|
75 |
// y copiar los registros que nos interesan (opci?n f?cil) |
|
76 |
// o implementar un listener que vaya vigilando los |
|
77 |
// arcos que se est?n evaluando dentro del algoritmo de |
|
78 |
// dijkstra. |
|
79 |
// Primero opci?n f?cil |
|
80 |
// Recorremos la capa, vemos en qu? intervalo cae cada |
|
81 |
// entidad y escribimos un shape. |
|
82 |
extractor.doExtract(0); |
|
83 |
|
|
84 |
|
|
85 |
long t2 = System.currentTimeMillis(); |
|
86 |
System.out.println("tiempo:" + (t2-t1)); |
|
87 |
|
|
88 |
// assertEquals(dist.doubleValue(), 8887, 0); |
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
} |
|
0 | 97 |
trunk/extensions/extGraph_predes/src-test/com/iver/cit/gvsig/graphtests/AllTests.java | ||
---|---|---|
11 | 11 |
"Test for com.iver.cit.gvsig.graph.test"); |
12 | 12 |
//$JUnit-BEGIN$ |
13 | 13 |
suite.addTestSuite(TestLoader.class); |
14 |
suite.addTestSuite(TestAngle.class); |
|
14 | 15 |
//$JUnit-END$ |
15 | 16 |
return suite; |
16 | 17 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/solvers/OneToManySolver.java | ||
---|---|---|
74 | 74 |
|
75 | 75 |
private GvFlag sourceFlag; |
76 | 76 |
private boolean bExploreAll = false; // by default |
77 |
private double maxCost = Double.MAX_VALUE; |
|
78 |
private double maxDistance = Double.MAX_VALUE; |
|
77 | 79 |
|
78 | 80 |
|
79 | 81 |
|
... | ... | |
231 | 233 |
node.setStatus(GvNode.statWasInList); |
232 | 234 |
// TODO: BORRAR POR INDEX, NO AS?. ES M?S LENTO QUE SI BORRAMOS EL i-?simo. |
233 | 235 |
candidatos.remove(node); |
236 |
|
|
237 |
// Si hemos fijado un m?ximo coste de exploraci?n, lo |
|
238 |
// tenemos en cuenta para salir. |
|
239 |
if ((maxCost < bestNode.getBestCost()) || |
|
240 |
maxDistance < bestNode.getAccumulatedLength()) |
|
241 |
{ |
|
242 |
bExit=true; |
|
243 |
} |
|
244 |
|
|
234 | 245 |
// System.out.println("LINK " + link.getIdArc() + " from "); |
235 | 246 |
// System.out.println("from " + idStart + " to " + finalNode.getIdNode() + ". node=" + node.getIdNode()); |
236 | 247 |
if (!bExploreAll) |
... | ... | |
389 | 400 |
public void setExploreAllNetwork(boolean b) { |
390 | 401 |
bExploreAll = b; |
391 | 402 |
} |
403 |
public double getMaxCost() { |
|
404 |
return maxCost; |
|
405 |
} |
|
406 |
public void setMaxCost(double maxCost) { |
|
407 |
this.maxCost = maxCost; |
|
408 |
} |
|
409 |
public double getMaxDistance() { |
|
410 |
return maxDistance; |
|
411 |
} |
|
412 |
public void setMaxDistance(double maxDistance) { |
|
413 |
this.maxDistance = maxDistance; |
|
414 |
} |
|
392 | 415 |
|
393 | 416 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/solvers/ServiceAreaExtractor.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 |
// 18/09/2007 fjp |
|
43 |
// @author: Fco. Jos? Pe?arrubia fpenarru@gmail.com |
|
44 |
|
|
45 |
package com.iver.cit.gvsig.graph.solvers; |
|
46 |
|
|
47 |
import java.io.File; |
|
48 |
import java.sql.Types; |
|
49 |
|
|
50 |
import org.gvsig.exceptions.BaseException; |
|
51 |
|
|
52 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
|
53 |
import com.hardcode.gdbms.engine.values.Value; |
|
54 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
55 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException; |
|
56 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
57 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
58 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
59 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
60 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
|
61 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
|
62 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
63 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
64 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
|
65 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
66 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
|
67 |
import com.iver.cit.gvsig.graph.core.EdgePair; |
|
68 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
|
69 |
import com.iver.cit.gvsig.graph.core.GvNode; |
|
70 |
import com.iver.cit.gvsig.graph.core.IGraph; |
|
71 |
import com.iver.cit.gvsig.graph.core.Network; |
|
72 |
|
|
73 |
/** |
|
74 |
* @author fjp |
|
75 |
* |
|
76 |
* This class can label nodes with distances and costs to a flag |
|
77 |
* Use first doLabelling() with every source flag and call |
|
78 |
* doExtract() to obtain a new layer with fields |
|
79 |
* IdArc, IdEdge, CostOrig, DistOrig, CostEnd, DistEnd, IdFlag |
|
80 |
* |
|
81 |
*/ |
|
82 |
public class ServiceAreaExtractor { |
|
83 |
private static String tempDirectoryPath = System.getProperty("java.io.tmpdir"); |
|
84 |
static FieldDescription[] fields = new FieldDescription[7]; |
|
85 |
static { |
|
86 |
FieldDescription fieldDesc = new FieldDescription(); |
|
87 |
fieldDesc.setFieldName("IDARC"); |
|
88 |
fieldDesc.setFieldType(Types.INTEGER); |
|
89 |
fieldDesc.setFieldLength(20); |
|
90 |
fieldDesc.setFieldDecimalCount(0); |
|
91 |
fields[0] = fieldDesc; |
|
92 |
|
|
93 |
fieldDesc = new FieldDescription(); |
|
94 |
fieldDesc.setFieldName("IDEDGE"); |
|
95 |
fieldDesc.setFieldType(Types.INTEGER); |
|
96 |
fieldDesc.setFieldLength(20); |
|
97 |
fieldDesc.setFieldDecimalCount(0); |
|
98 |
fields[1] = fieldDesc; |
|
99 |
|
|
100 |
fieldDesc = new FieldDescription(); |
|
101 |
fieldDesc.setFieldName("COSTORIG"); |
|
102 |
fieldDesc.setFieldType(Types.DOUBLE); |
|
103 |
fieldDesc.setFieldLength(20); |
|
104 |
fieldDesc.setFieldDecimalCount(5); |
|
105 |
fields[2] = fieldDesc; |
|
106 |
|
|
107 |
fieldDesc = new FieldDescription(); |
|
108 |
fieldDesc.setFieldName("DISTORIG"); |
|
109 |
fieldDesc.setFieldType(Types.DOUBLE); |
|
110 |
fieldDesc.setFieldLength(20); |
|
111 |
fieldDesc.setFieldDecimalCount(5); |
|
112 |
fields[3] = fieldDesc; |
|
113 |
|
|
114 |
fieldDesc = new FieldDescription(); |
|
115 |
fieldDesc.setFieldName("COSTEND"); |
|
116 |
fieldDesc.setFieldType(Types.DOUBLE); |
|
117 |
fieldDesc.setFieldLength(20); |
|
118 |
fieldDesc.setFieldDecimalCount(5); |
|
119 |
fields[4] = fieldDesc; |
|
120 |
|
|
121 |
fieldDesc = new FieldDescription(); |
|
122 |
fieldDesc.setFieldName("DISTEND"); |
|
123 |
fieldDesc.setFieldType(Types.DOUBLE); |
|
124 |
fieldDesc.setFieldLength(20); |
|
125 |
fieldDesc.setFieldDecimalCount(5); |
|
126 |
fields[5] = fieldDesc; |
|
127 |
|
|
128 |
fieldDesc = new FieldDescription(); |
|
129 |
fieldDesc.setFieldName("IDFLAG"); |
|
130 |
fieldDesc.setFieldType(Types.INTEGER); |
|
131 |
fieldDesc.setFieldLength(20); |
|
132 |
fieldDesc.setFieldDecimalCount(5); |
|
133 |
fields[6] = fieldDesc; |
|
134 |
|
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
private Network net; |
|
139 |
private ShpWriter shpWriter; |
|
140 |
private File fTemp; |
|
141 |
private SHPLayerDefinition layerDef; |
|
142 |
|
|
143 |
public ServiceAreaExtractor(Network net) throws InitializeWriterException { |
|
144 |
this.net = net; |
|
145 |
int aux = (int)(Math.random() * 1000); |
|
146 |
fTemp = new File(tempDirectoryPath + "/tmpShp" + aux + ".shp"); |
|
147 |
|
|
148 |
layerDef = new SHPLayerDefinition(); |
|
149 |
layerDef.setFile(fTemp); |
|
150 |
layerDef.setName("TestLayer"); |
|
151 |
layerDef.setFieldsDesc(fields); |
|
152 |
layerDef.setShapeType(FShape.LINE); |
|
153 |
|
|
154 |
shpWriter = new ShpWriter(); |
|
155 |
shpWriter.setFile(fTemp); |
|
156 |
shpWriter.initialize(layerDef); |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
public void doExtract(int idFlag) { |
|
161 |
FLyrVect lyr = net.getLayer(); |
|
162 |
IGraph g = net.getGraph(); |
|
163 |
ReadableVectorial adapter = lyr.getSource(); |
|
164 |
try { |
|
165 |
|
|
166 |
shpWriter.preProcess(); |
|
167 |
adapter.start(); |
|
168 |
|
|
169 |
for (int i=0; i < adapter.getShapeCount(); i++) |
|
170 |
{ |
|
171 |
IGeometry geom = adapter.getShape(i); |
|
172 |
EdgePair edgePair = g.getEdgesByIdArc(i); |
|
173 |
if (edgePair.getIdEdge() != -1) |
|
174 |
{ |
|
175 |
GvEdge edge = g.getEdgeByID(edgePair.getIdEdge()); |
|
176 |
GvNode nodeEnd = g.getNodeByID(edge.getIdNodeEnd()); |
|
177 |
GvNode nodeOrig = g.getNodeByID(edge.getIdNodeOrig()); |
|
178 |
if (nodeEnd.getBestCost() < Double.MAX_VALUE) { |
|
179 |
// A ese tramo hemos llegado por completo |
|
180 |
// Recuperamos su distancia y etiquetamos. |
|
181 |
writeTotalEdge(i, geom, edge, nodeOrig, nodeEnd, idFlag); |
|
182 |
} |
|
183 |
else |
|
184 |
{ |
|
185 |
if (nodeOrig.getBestCost() < Double.MAX_VALUE) { |
|
186 |
// A ese tramo hemos llegado parcialmente |
|
187 |
// Recuperamos su distancia y etiquetamos. |
|
188 |
writePartialEdge(i, geom, edge, nodeOrig, nodeEnd, idFlag); |
|
189 |
|
|
190 |
} |
|
191 |
} // else |
|
192 |
} |
|
193 |
if (edgePair.getIdInverseEdge() != -1) |
|
194 |
{ |
|
195 |
GvEdge inversedEdge = g.getEdgeByID(edgePair.getIdInverseEdge()); |
|
196 |
GvNode nodeEnd = g.getNodeByID(inversedEdge.getIdNodeEnd()); |
|
197 |
GvNode nodeOrig = g.getNodeByID(inversedEdge.getIdNodeOrig()); |
|
198 |
if (nodeEnd.getBestCost() < Double.MAX_VALUE) { |
|
199 |
// A ese tramo hemos llegado por completo |
|
200 |
// Recuperamos su distancia y etiquetamos. |
|
201 |
writeTotalEdge(i, geom, inversedEdge, nodeOrig, nodeEnd, idFlag); |
|
202 |
} |
|
203 |
else |
|
204 |
{ |
|
205 |
if (nodeOrig.getBestCost() < Double.MAX_VALUE) { |
|
206 |
// A ese tramo hemos llegado parcialmente |
|
207 |
// Recuperamos su distancia y etiquetamos. |
|
208 |
writePartialEdge(i, geom, inversedEdge, nodeOrig, nodeEnd, idFlag); |
|
209 |
|
|
210 |
} |
|
211 |
} // else |
|
212 |
} |
|
213 |
|
|
214 |
} |
|
215 |
shpWriter.postProcess(); |
|
216 |
adapter.stop(); |
|
217 |
} catch (BaseException e) { |
|
218 |
// TODO Auto-generated catch block |
|
219 |
e.printStackTrace(); |
|
220 |
} |
|
221 |
|
|
222 |
|
|
223 |
} |
|
224 |
|
|
225 |
private void writePartialEdge(int i, IGeometry geom, GvEdge edge, GvNode nodeOrig, GvNode nodeEnd, int idFlag) { |
|
226 |
// TODO Auto-generated method stub |
|
227 |
|
|
228 |
} |
|
229 |
|
|
230 |
private void writeTotalEdge(int i, IGeometry geom, GvEdge edge, GvNode nodeOrig, GvNode nodeEnd, int idFlag) throws ProcessWriterVisitorException { |
|
231 |
Value[] values = new Value[7]; |
|
232 |
values[0] = ValueFactory.createValue(i); |
|
233 |
values[1] = ValueFactory.createValue(edge.getIdEdge()); |
|
234 |
values[2] = ValueFactory.createValue(nodeOrig.getBestCost()); |
|
235 |
values[3] = ValueFactory.createValue(nodeOrig.getAccumulatedLength()); |
|
236 |
values[4] = ValueFactory.createValue(nodeEnd.getBestCost()); |
|
237 |
values[5] = ValueFactory.createValue(nodeEnd.getAccumulatedLength()); |
|
238 |
values[6] = ValueFactory.createValue(idFlag); |
|
239 |
|
|
240 |
|
|
241 |
DefaultFeature feat = new DefaultFeature(geom, values); |
|
242 |
IRowEdited row = new DefaultRowEdited(feat, DefaultRowEdited.STATUS_ADDED, i); |
|
243 |
shpWriter.process(row); |
|
244 |
} |
|
245 |
|
|
246 |
} |
|
0 | 247 |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/preferences/RoutePage.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.10 2007-09-07 11:29:47 fjp |
|
46 |
* Revision 1.11 2007-09-19 14:28:27 fjp |
|
47 |
* Test case para ServiceArea y los ficheros de prueba con los ejes de Madrid. |
|
48 |
* |
|
49 |
* Revision 1.10 2007/09/07 11:29:47 fjp |
|
47 | 50 |
* Casi compila. Falta arreglar lo de FArrowSymbol y retocar el graphiclist de FMap. |
48 | 51 |
* |
49 | 52 |
* Revision 1.9 2007/01/16 11:51:07 jaume |
... | ... | |
94 | 97 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
95 | 98 |
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer; |
96 | 99 |
import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
100 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector; |
|
97 | 101 |
|
98 | 102 |
public class RoutePage extends AbstractPreferencePage { |
99 | 103 |
private ImageIcon icon; |
... | ... | |
114 | 118 |
aux.add(btnChangeSymbol = new JButton(PluginServices.getText(this, "change"))); |
115 | 119 |
btnChangeSymbol.addActionListener(new ActionListener() { |
116 | 120 |
public void actionPerformed(ActionEvent e) { |
117 |
SymbolSelector symbSelec = new SymbolSelector(null, FShape.POLYGON);
|
|
121 |
ISymbolSelector symbSelec = SymbolSelector.createSymbolSelector(null, FShape.LINE);
|
|
118 | 122 |
PluginServices.getMDIManager().addWindow(symbSelec); |
119 | 123 |
ISymbol sym = (ISymbol) symbSelec.getSelectedObject(); |
120 | 124 |
if (sym!=null) |
Also available in: Unified diff