Revision 20259

View differences:

trunk/libraries/libTopology/src/org/gvsig/jts/JtsUtil.java
93 93
import com.vividsolutions.jts.geomgraph.GeometryGraph;
94 94
import com.vividsolutions.jump.util2.CoordinateArrays;
95 95

  
96
import es.axios.udig.ui.editingtools.internal.geometryoperations.split.SplitStrategy;
97

  
96 98
/**
97 99
 * Utility methods for JTS library use.
98 100
 * 
......
458 460
	}
459 461
	
460 462
	//TODO REESCRIBIR ESTO CON GENERICS
461
	
463
//	/**
464
//     * Adapts a Geometry <code>geom</code> to another type of geometry given the desired geometry
465
//     * class.
466
//     * <p>
467
//     * Currently implemented adaptations:
468
//     * <ul>
469
//     * <li>Point -> MultiPoint. Wraps the Point on a single part MultiPoint.
470
//     * <li>Polygon -> MultiPolygon. Wraps the Polygon on a single part MultiPolygon.
471
//     * <li>LineString -> MultiLineString. Wraps the LineString on a single part MultiLineString.
472
//     * <li>MultiLineString -> String. Succeeds if merging the parts result in a single LineString,
473
//     * fails otherwise.
474
//     * <li>MultiPolygon -> Polygon. Succeeds if merging the parts result in a single Polygon, fails
475
//     * otherwise.
476
//     * <li>* -> GeometryCollection
477
//     * </ul>
478
//     * </p>
479
//     * TODO: add more adaptations on an as needed basis
480
//     * 
481
//     * @param inputGeom
482
//     * @param adaptTo
483
//     * @return a new Geometry adapted
484
//     * @throws IllegalArgumentException if <code>geom</code> cannot be adapted as
485
//     *         <code>adapTo</code>
486
//     */
487
//    public static Geometry adapt( final Geometry inputGeom, final Class< ? extends Geometry> adaptTo ) {
488
//
489
//        assert inputGeom != null : "inputGeom can't be null";
490
//        assert adaptTo != null : "adaptTo can't be null";;
491
//
492
//        final Class<?> geomClass = inputGeom.getClass();
493
//
494
//        if (Geometry.class.equals(adaptTo)) {
495
//            return inputGeom;
496
//        }
497
//
498
//        final GeometryFactory gf = inputGeom.getFactory();
499
//       
500
//        if (MultiPoint.class.equals(adaptTo) && Point.class.equals(geomClass)) {
501
//            return gf.createMultiPoint(new Point[]{(Point) inputGeom});
502
//        }
503
//
504
//        if (Polygon.class.equals(adaptTo)) {
505
//            if (adaptTo.equals(geomClass)) {
506
//                return inputGeom;
507
//            }
508
//            Polygonizer polygonnizer = new Polygonizer();
509
//            polygonnizer.add(inputGeom);
510
//            Collection polys = polygonnizer.getPolygons();
511
//            Polygon[] polygons = new ArrayList<Polygon>(polys).toArray(new Polygon[polys.size()]);
512
//
513
//            if (polygons.length == 1) {
514
//                return polygons[0];
515
//            }
516
//        }
517
//
518
//        if (MultiPolygon.class.equals(adaptTo)) {
519
//            if (adaptTo.equals(geomClass)) {
520
//                return inputGeom;
521
//            }
522
//            if (Polygon.class.equals(geomClass)) {
523
//                return gf.createMultiPolygon(new Polygon[]{(Polygon) inputGeom});
524
//            }
525
//            /*
526
//             * Polygonizer polygonnizer = new Polygonizer(); polygonnizer.add(inputGeom); Collection
527
//             * polys = polygonnizer.getPolygons(); Polygon[] polygons = new ArrayList<Polygon>(polys).toArray(new
528
//             * Polygon[polys.size()]); if (MultiPolygon.class.equals(adaptTo)) { return
529
//             * gf.createMultiPolygon(polygons); } if (polygons.length == 1) { return polygons[0]; }
530
//             */
531
//        }
532
//
533
//        if (GeometryCollection.class.equals(adaptTo)) {
534
//            return gf.createGeometryCollection(new Geometry[]{inputGeom});
535
//        }
536
//
537
//        if (MultiLineString.class.equals(adaptTo) || LineString.class.equals(adaptTo)) {
538
//            LineMerger merger = new LineMerger();
539
//            merger.add(inputGeom);
540
//            Collection mergedLineStrings = merger.getMergedLineStrings();
541
//            ArrayList<LineString> lineList = new ArrayList<LineString>(mergedLineStrings);
542
//            LineString[] lineStrings = lineList.toArray(new LineString[mergedLineStrings.size()]);
543
//
544
//            if (MultiLineString.class.equals(adaptTo)) {
545
//                MultiLineString line = gf.createMultiLineString(lineStrings);
546
//                return line;
547
//            }
548
//            if (lineStrings.length == 1) {
549
//                Geometry mergedResult = (Geometry) lineStrings[0];
550
//                return mergedResult;
551
//            }
552
//        }
553
//        if(Polygon.class.equals(adaptTo) && (MultiPolygon.class.equals(geomClass))){
554
//            // adapts multipolygon to polygon
555
//            
556
//            assert inputGeom.getNumGeometries() == 1 : "the collection must have 1 element to adapt to Polygon";
557
//            return inputGeom.getGeometryN(1);
558
//        
559
//        } else if(LineString.class.equals(adaptTo) && (MultiLineString.class.equals(geomClass))){
560
//            // adapts MultiLinestring to Linestring
561
//            
562
//            assert inputGeom.getNumGeometries() == 1 : "the collection must have 1 element to adapt to Polygon";
563
//            return inputGeom.getGeometryN(1);
564
//        }
565
//
566
//        final String msg = MessageFormat.format(Messages.GeometryUtil_DonotKnowHowAdapt,
567
//                                                geomClass.getSimpleName(), adaptTo.getSimpleName());
568
//
569
//        throw new IllegalArgumentException(msg);
570
//    }
462 571
	public static LineString[] extractLineStrings(Geometry g){
463 572
		LineString[] solution = null;
464 573
		List<LineString> solutionList = new ArrayList<LineString>();
......
673 782
		else
674 783
			return false;
675 784
	}
785
	
786
	
787
	public static Geometry split(Geometry geom, LineString line){
788
		return SplitStrategy.splitOp(geom, line);
789
	}
676 790
}

Also available in: Unified diff