Revision 8402 trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/core/NetworkWriter.java

View differences:

NetworkWriter.java
47 47
import java.nio.ByteOrder;
48 48
import java.sql.Types;
49 49
import java.util.ArrayList;
50
import java.util.Collection;
51 50
import java.util.Hashtable;
52
import java.util.Iterator;
53 51

  
54 52
import javax.imageio.stream.FileImageOutputStream;
55 53

  
54
import com.hardcode.gdbms.engine.values.IntValue;
56 55
import com.hardcode.gdbms.engine.values.NumericValue;
57 56
import com.hardcode.gdbms.engine.values.Value;
58 57
import com.hardcode.gdbms.engine.values.ValueFactory;
59
import com.iver.andami.PluginServices;
60 58
import com.iver.cit.gvsig.fmap.DriverException;
61 59
import com.iver.cit.gvsig.fmap.core.DefaultRow;
62 60
import com.iver.cit.gvsig.fmap.core.FShape;
......
72 70
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
73 71
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
74 72
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
75
import com.iver.cit.gvsig.project.documents.view.legend.CreateSpatialIndexMonitorableTask;
76
import com.iver.utiles.swing.threads.AbstractMonitorableTask;
77 73
import com.iver.utiles.swing.threads.CancellableMonitorable;
78 74
import com.vividsolutions.jts.geom.Coordinate;
79 75
import com.vividsolutions.jts.geom.Geometry;
......
381 377
		// con su velocidad. Esa velocidad se fijar? en la funci?n
382 378
		// FijaVelocidades. OJO, empezar siempre desde el 0
383 379

  
384
		float distance;
380
		double distance, cost;
385 381
		short arcType;
386 382
		int direction;
387 383
		int i;
......
435 431
			edgeCount = 0;
436 432

  
437 433
			SelectableDataSource sds = lyrSrc.getRecordset();
438
			int senseFieldIndex = sds.getFieldIndexByName(fieldSense);
439
			int distFieldIndex = sds.getFieldIndexByName(fieldDist);
440
			int typeFieldIndex = sds.getFieldIndexByName(fieldType);
441
			if (typeFieldIndex == -1) {
442
				throw new RuntimeException("Field invalid:" + fieldType);
443
			}
444
			if (distFieldIndex == -1) {
445
				throw new RuntimeException("Field invalid:" + fieldDist);
446
			}
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 447

  
448
			NumericValue valAux = null;
448 449
			for (i = 0; i < numTramos; i++) {
449 450
				IGeometry geom = adapter.getShape(i);
450 451
				Geometry jtsGeom = geom.toJTSGeometry();
......
479 480
				}
480 481
				idNodo2 = nodeAux.getId().intValue();
481 482

  
482
				NumericValue valAux = (NumericValue) sds.getFieldValue(i,
483
						typeFieldIndex);
483
				if (typeFieldIndex != -1)
484
					valAux = (NumericValue) sds.getFieldValue(i, typeFieldIndex);
485
				else
486
					valAux = ValueFactory.createValue(0); // no hay tipo
484 487
				arcType = valAux.shortValue();
485 488
				// TipoTramo = DBFReadIntegerAttribute(hDBF, i, indiceCampo1);
486
				valAux = (NumericValue) sds.getFieldValue(i, distFieldIndex);
489
				
490
				if (distFieldIndex != -1)
491
					valAux = (NumericValue) sds.getFieldValue(i, distFieldIndex);
492
				else
493
					valAux = ValueFactory.createValue(jtsGeom.getLength());
487 494
				distance = valAux.floatValue();
488 495
				// Distancia = (float) DBFReadDoubleAttribute(hDBF, i,
489 496
				// indiceCampo2);
497
				if (costFieldIndex != -1)
498
				{
499
					valAux = (NumericValue) sds.getFieldValue(i, costFieldIndex);
500
					cost = valAux.doubleValue();
501
				}
502
				else
503
					cost = distance;
504
				
505
				
490 506

  
491 507
				direction = -1;
492 508

  
......
503 519
				if (direction == 3) {
504 520
					sentidoDigit = 1; // En esa direcci?n
505 521
					writeEdge(output, i, sentidoDigit, idNodo1, idNodo2, arcType,
506
							distance);
522
							distance, cost);
507 523
					edgeCount++;
508 524

  
509 525
					sentidoDigit = 0;
510 526
					writeEdge(output, i, sentidoDigit, idNodo2, idNodo1, arcType,
511
							distance);
527
							distance, cost);
512 528
					edgeCount++;
513 529

  
514 530
				}
515 531
				if (direction == 1) {
516 532
					sentidoDigit = 1; // En esa direcci?n
517 533
					writeEdge(output, i, sentidoDigit, idNodo1, idNodo2, arcType,
518
							distance);
534
							distance, cost);
519 535
					edgeCount++;
520 536
				}
521 537
				if (direction == 2) {
522 538
					sentidoDigit = 0;
523 539
					writeEdge(output, i, sentidoDigit, idNodo2, idNodo1, arcType,
524
							distance);
540
							distance, cost);
525 541
					edgeCount++;
526 542

  
527 543
				}
......
573 589
	}
574 590

  
575 591
	private void writeEdge(FileImageOutputStream output, int id, short sense,
576
			int idNodeOrig, int idNodeEnd, short tipoTramo, float dist)
592
			int idNodeOrig, int idNodeEnd, short tipoTramo, double dist, double cost)
577 593
			throws IOException {
578 594
		output.writeInt(id);
579 595
		output.writeInt(sense);
......
581 597
		output.writeInt(idNodeOrig);
582 598
		output.writeInt(idNodeEnd);
583 599
		output.writeInt(tipoTramo);
584
		output.writeFloat(dist);
600
		output.writeDouble(dist);
601
		output.writeDouble(cost);
585 602

  
586 603
	}
587 604

  

Also available in: Unified diff