Revision 12565

View differences:

branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/topology/lineclean/fmap/LineCleanVisitor.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.7  2006-11-14 18:34:16  azabala
48
 * Revision 1.7.2.1  2007-07-12 12:20:51  azabala
49
 * bug solved
50
 *
51
 * Revision 1.7  2006/11/14 18:34:16  azabala
49 52
 * *** empty log message ***
50 53
 *
51 54
 * Revision 1.6  2006/11/14 18:01:09  azabala
......
519 522

  
520 523
			// It computes linear distance of a point on the given jtsGeo linear
521 524
			// geometry
522
			LengthIndexedLine lengthLine = new LengthIndexedLine(jtsGeo);
523
			Iterator nodesIt = nodes.iterator();
524
			ArrayList nodeIntersections = new ArrayList();
525
			while (nodesIt.hasNext()) {
526
				Node node = (Node) nodesIt.next();
527
				Coordinate coord = node.getCoordinate();
528
				double lengthOfNode = lengthLine.indexOf(coord);
529
				LineIntersection inters = new LineIntersection();
530
				inters.coordinate = coord;
531
				inters.lenght = lengthOfNode;
532
				nodeIntersections.add(inters);
533
			}
525
			boolean rightGeometry = true;
526
			if (nodes.values().size() > 0) {
527
				
528
				LengthIndexedLine lengthLine = new LengthIndexedLine(jtsGeo);
529
				Iterator nodesIt = nodes.iterator();
530
				ArrayList nodeIntersections = new ArrayList();
531
				while (nodesIt.hasNext()) {
532
					Node node = (Node) nodesIt.next();
533
					Coordinate coord = node.getCoordinate();
534
					double lengthOfNode = lengthLine.indexOf(coord);
535
					LineIntersection inters = new LineIntersection();
536
					inters.coordinate = coord;
537
					inters.lenght = lengthOfNode;
538
					nodeIntersections.add(inters);
539
				}
540
				
541
				if (nodeIntersections.size() > 0) {
542
					// We sort the intersections by distance along the line
543
					// (dynamic
544
					// segmentation)
545
					rightGeometry = false;
546
					Collections.sort(nodeIntersections, new Comparator() {
547
						public int compare(Object arg0, Object arg1) {
548
							LineIntersection l1 = (LineIntersection) arg0;
549
							LineIntersection l2 = (LineIntersection) arg1;
550
							if (l1.lenght > l2.lenght)
551
								return 1;
552
							else if (l1.lenght < l2.lenght)
553
								return -1;
554
							else
555
								return 0;
556
						}
557
					});
534 558

  
535
			if (nodeIntersections.size() > 0) {
536
				//	We sort the intersections by distance along the line (dynamic
537
				// segmentation)
538
				Collections.sort(nodeIntersections, new Comparator() {
539
					public int compare(Object arg0, Object arg1) {
540
						LineIntersection l1 = (LineIntersection) arg0;
541
						LineIntersection l2 = (LineIntersection) arg1;
542
						if (l1.lenght > l2.lenght)
543
							return 1;
544
						else if (l1.lenght < l2.lenght)
545
							return -1;
546
						else
547
							return 0;
548
					}
549
				});
559
					LinearLocation lastLocation = null;
560
					LineIntersection lastIntersection = null;
561
					LocationIndexedLine indexedLine = new LocationIndexedLine(
562
							jtsGeo);
563
					for (int i = 0; i < nodeIntersections.size(); i++) {
564
						Geometry solution = null;
565
						LineIntersection li = (LineIntersection) nodeIntersections
566
								.get(i);
550 567

  
551
				LinearLocation lastLocation = null;
552
				LineIntersection lastIntersection = null;
553
				LocationIndexedLine indexedLine = new LocationIndexedLine(
554
						jtsGeo);
555
				for (int i = 0; i < nodeIntersections.size(); i++) {
556
					Geometry solution = null;
557
					LineIntersection li = (LineIntersection) nodeIntersections
558
							.get(i);
559
					
560
					LinearLocation location = indexedLine
561
							.indexOf(li.coordinate);
562
					if (lastLocation == null) {
563
						LinearLocation from = new LinearLocation(0, 0d);
564
						solution = splitLineString(jtsGeo, from, location,
565
								null, li);
566
						lastLocation = location;
567
						lastIntersection = li;
568
						/*
569
						 * Construimos una linea desde el primer punto hasta el
570
						 * punto contenido en LineIntersection, con todos los
571
						 * puntos intermedios de la linea.
572
						 * 
573
						 * 
574
						 * 
575
						 */
576
					} else {
577
						// Construimos una linea entre lastIntersection y la
578
						// intersection
579
						// actual
580
						LinearLocation locationFrom = lastLocation;
581
						solution = splitLineString(jtsGeo, locationFrom,
582
								location, lastIntersection, li);
583
						lastLocation = location;
584
						lastIntersection = li;
568
						LinearLocation location = indexedLine
569
								.indexOf(li.coordinate);// es posible que esto
570
														// est? mal por no
571
														// pasarle una longitud.
572
														// REVISAR
573
						if (lastLocation == null) {
574
							LinearLocation from = new LinearLocation(0, 0d);
575
							
576
//							solution = splitLineString(jtsGeo, from, location,
577
//									null, li);
578
//							
579
							
580
							solution = indexedLine.extractLine(from, location);
581
							
582
							
583
							lastLocation = location;
584
							lastIntersection = li;
585
							/*
586
							 * Construimos una linea desde el primer punto hasta
587
							 * el punto contenido en LineIntersection, con todos
588
							 * los puntos intermedios de la linea.
589
							 * 
590
							 * 
591
							 * 
592
							 */
593
						} else {
594
							// Construimos una linea entre lastIntersection y la
595
							// intersection
596
							// actual
597
							LinearLocation locationFrom = lastLocation;
598
							
599
//							solution = splitLineString(jtsGeo, locationFrom,
600
//									location, lastIntersection, li);
601
							
602
							solution = indexedLine.extractLine(locationFrom, location);
603
							lastLocation = location;
604
							lastIntersection = li;
585 605

  
586
					}
606
						}
587 607

  
588
					
589 608
						IFeature feature = createFeature(solution, index);
590 609
						featureProcessor.processFeature(feature);
591 610
						// TODO Podriamos guardar los puntos de interseccion
592 611
						// para
593 612
						// mostrar al usuario que puntos eran pseudonodos
594
				}// for
595
				
596
				//a?adimos el ultimo segmento
597
				Coordinate[] geomCoords = jtsGeo.getCoordinates();
598
				ArrayList coordinates = new ArrayList();
599
				coordinates.add(lastIntersection.coordinate);
600
				int startIndex = lastLocation.getSegmentIndex() + 1;
601
				for (int i = startIndex; i < geomCoords.length; i++) {
602
					coordinates.add(geomCoords[i]);
613
					}// for
614

  
615
					// a?adimos el ultimo segmento
616
//					Coordinate[] geomCoords = jtsGeo.getCoordinates();
617
//					ArrayList coordinates = new ArrayList();
618
//					coordinates.add(lastIntersection.coordinate);
619
//					int startIndex = lastLocation.getSegmentIndex() + 1;
620
//					for (int i = startIndex; i < geomCoords.length; i++) {
621
//						coordinates.add(geomCoords[i]);
622
//					}
623
//					Coordinate[] solutionCoords = new Coordinate[coordinates
624
//							.size()];
625
//					coordinates.toArray(solutionCoords);
626
//					IFeature lastFeature = createFeature(new GeometryFactory()
627
//							.createLineString(solutionCoords), index);
628
					LinearLocation endLocation = new LinearLocation();
629
					endLocation.setToEnd(jtsGeo);
630
					Geometry geo = indexedLine.extractLine(lastLocation, endLocation);
631
					IFeature lastFeature = createFeature(geo, index);
632
					featureProcessor.processFeature(lastFeature);
633

  
603 634
				}
604
				Coordinate[] solutionCoords = new Coordinate[coordinates.size()];
605
				coordinates.toArray(solutionCoords);
606
				IFeature lastFeature = createFeature(new GeometryFactory().
607
										 createLineString(solutionCoords), 
608
										 index);
609
				featureProcessor.processFeature(lastFeature);
610
				
611
				
612
			} else {
635
			} 
636
			if(rightGeometry){
613 637
				IFeature feature = createFeature(g, index);
614 638
				featureProcessor.processFeature(feature);
615 639
			}
616 640

  
641

  
617 642
		} catch (com.iver.cit.gvsig.fmap.DriverException e) {
618 643
			throw new VisitException(
619 644
					"Error buscando los overlays que intersectan con un feature");

Also available in: Unified diff