Revision 19632 trunk/libraries/libTopology/src/org/gvsig/jts/GeometrySnapper.java

View differences:

GeometrySnapper.java
324 324
			for(int i = 0; i < numGeometries; i++){
325 325
				lineStrings[i] = (LineString) snap(multiLine.getGeometryN(i));
326 326
			}
327
			return JtsUtil.geomFactory.createMultiLineString(lineStrings);
327
			return JtsUtil.GEOMETRY_FACTORY.createMultiLineString(lineStrings);
328 328
			
329 329
		}else if(geom.getGeometryType().equalsIgnoreCase("MultiPolygon")){
330 330
			MultiPolygon multiPolygon = (MultiPolygon) geom;
......
333 333
			for(int i = 0; i < numGeometries; i++){
334 334
				polygons[i] = (Polygon) snap(multiPolygon.getGeometryN(i));
335 335
			}
336
			return JtsUtil.geomFactory.createMultiPolygon(polygons);
336
			return JtsUtil.GEOMETRY_FACTORY.createMultiPolygon(polygons);
337 337
			
338 338
			
339 339
		}else if(geom.getGeometryType().equalsIgnoreCase("GeometryCollection")){
......
343 343
			for(int i = 0; i < numGeometries; i++){
344 344
				geoms[i] = snap(geomCol.getGeometryN(i));
345 345
			}
346
			return JtsUtil.geomFactory.createGeometryCollection(geoms);
346
			return JtsUtil.GEOMETRY_FACTORY.createGeometryCollection(geoms);
347 347
		}else if(geom.getGeometryType().equalsIgnoreCase("LineString") || 
348 348
					geom.getGeometryType().equalsIgnoreCase("LinearRing")){
349 349
			coords = ((LineString)geom).getCoordinates();
......
357 357
				LineString hole = polygon.getInteriorRingN(i);
358 358
				newHoles[i] = (LinearRing) snap(hole);
359 359
			}
360
			return JtsUtil.geomFactory.createPolygon(snapedShell, newHoles);
360
			return JtsUtil.GEOMETRY_FACTORY.createPolygon(snapedShell, newHoles);
361 361
		}
362 362
		
363 363
		SnapCoordinateList snapCoordList = 
......
441 441
	}
442 442
		
443 443
	
444
	public boolean isClosed(Geometry a) {
445
		Coordinate[] coords = a.getCoordinates();
446
		Coordinate firstPoint = coords[0];
447
		Coordinate lastPoint = coords[coords.length - 1];
448
		return SnapCGAlgorithms.snapEquals2D(firstPoint, lastPoint,
449
				snapTolerance);
450
	}
451
	
452 444
	/**
453 445
	 * If geometry 'a' is not exactly closed, but its extremes are 
454 446
	 * in a snap radius, its snap the last point to the first point of the
......
460 452
		Coordinate[] coords = a.getCoordinates();
461 453
		Coordinate firstPoint = coords[0];
462 454
		Coordinate lastPoint = coords[coords.length - 1];
463
		if(!firstPoint.equals2D(lastPoint) && isClosed(a)){
455
		if(!firstPoint.equals2D(lastPoint) && JtsUtil.isClosed(a, snapTolerance)){
464 456
		    CoordinateList coordList = new CoordinateList(coords);
465 457
		    coordList.set(coords.length - 1, coords[0]);
466 458
//		    return createGeometry(coordList.toCoordinateArray(), a);
......
470 462
			return a;
471 463
	}
472 464
	
473
	public static boolean isClosed(Geometry a, double snap){
474
		Coordinate[] coords = a.getCoordinates();
475
		Coordinate firstPoint = coords[0];
476
		Coordinate lastPoint = coords[coords.length - 1];
477
		return SnapCGAlgorithms.snapEquals2D(firstPoint, lastPoint, snap);
478
	}
479 465
	
480
	
481 466
	/**
482 467
	 * Snaps coordinates in srcPts with coordinates of snapPts.
483 468
	 * This method forces the snap: the points of srcPoints are shifted to

Also available in: Unified diff