private static Geometry smooth( final Geometry geom, final double fit, final GeometryFactory factory, GeometrySmoother smoother) { switch (Geometries.get(geom)) { case POINT: case MULTIPOINT: // For points, just return the input geometry return geom; case LINESTRING: // This handles open and closed lines (LinearRings) return smoothLineString(factory, smoother, geom, fit); case MULTILINESTRING: return smoothMultiLineString(factory, smoother, geom, fit); case POLYGON: return smoother.smooth((Polygon) geom, fit); case MULTIPOLYGON: return smoothMultiPolygon(factory, smoother, geom, fit); case GEOMETRYCOLLECTION: return smoothGeometryCollection(factory, smoother, geom, fit); default: throw new UnsupportedOperationException( "No smoothing method available for " + geom.getGeometryType()); } }
public DBObject toObject(Geometry geom) { Geometries g = Geometries.get(geom); switch (g) { case POINT: return toObject((Point) geom); case LINESTRING: return toObject((LineString) geom); case POLYGON: return toObject((Polygon) geom); case MULTIPOINT: return toObject((MultiPoint) geom); case MULTILINESTRING: return toObject((MultiLineString) geom); case MULTIPOLYGON: return toObject((MultiPolygon) geom); case GEOMETRYCOLLECTION: return toObject((GeometryCollection) geom); default: throw new IllegalArgumentException("Unknown geometry type: " + geom); } }
@Test public void testGetByObject() { // System.out.println(" get (by object)"); Geometry point = geomFactory.createPoint(coords[0]); assertEquals(Geometries.POINT, Geometries.get(point)); Geometry multiPoint = geomFactory.createMultiPoint(coords); assertEquals(Geometries.MULTIPOINT, Geometries.get(multiPoint)); Geometry line = geomFactory.createLineString(coords); assertEquals(Geometries.LINESTRING, Geometries.get(line)); LineString[] lines = { geomFactory.createLineString(new Coordinate[] {coords[0], coords[1]}), geomFactory.createLineString(new Coordinate[] {coords[2], coords[3]}) }; Geometry multiLine = geomFactory.createMultiLineString(lines); assertEquals(Geometries.MULTILINESTRING, Geometries.get(multiLine)); Polygon poly = geomFactory.createPolygon(geomFactory.createLinearRing(coords), null); assertEquals(Geometries.POLYGON, Geometries.get(poly)); Polygon[] polys = {poly, poly}; Geometry multiPoly = geomFactory.createMultiPolygon(polys); assertEquals(Geometries.MULTIPOLYGON, Geometries.get(multiPoly)); Geometry gc = geomFactory.createGeometryCollection(polys); assertEquals(Geometries.GEOMETRYCOLLECTION, Geometries.get(gc)); }