/** * Computes a {@link Geometry} containing only {@link Polygonal} components. * Extracts the {@link Polygon}s from the input * and returns them as an appropriate {@link Polygonal} geometry. * <p> * If the input is already <tt>Polygonal</tt>, it is returned unchanged. * <p> * A particular use case is to filter out non-polygonal components * returned from an overlay operation. * * @param g the geometry to filter * @return a Polygonal geometry */ private static Geometry restrictToPolygons(Geometry g) { if (g instanceof Polygonal) { return g; } List polygons = PolygonExtracter.getPolygons(g); if (polygons.size() == 1) return (Polygon) polygons.get(0); return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons)); } }
if (isCollection) { if (geom0 instanceof Polygon) { return createMultiPolygon(toPolygonArray(geomList));
/** * Removes duplicated coordinates within a MultiPolygon. * @param g * @return */ public static MultiPolygon removeDuplicateCoordinates(MultiPolygon g) { ArrayList<Polygon> polys = new ArrayList<Polygon>(); for (int i = 0; i < g.getNumGeometries(); i++) { Polygon poly = (Polygon) g.getGeometryN(i); polys.add(removeDuplicateCoordinates(poly)); } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys)); }
/** * Removes duplicated coordinates within a MultiPolygon. * * @param g * @return */ public static MultiPolygon removeCoordinates(MultiPolygon g) { ArrayList<Polygon> polys = new ArrayList<Polygon>(); for (int i = 0; i < g.getNumGeometries(); i++) { Polygon poly = (Polygon) g.getGeometryN(i); polys.add(removeCoordinates(poly)); } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys)); }
/** * Removes duplicated coordinates within a MultiPolygon. * * @param g * @return */ public static MultiPolygon removeCoordinates(MultiPolygon g) { ArrayList<Polygon> polys = new ArrayList<Polygon>(); for (int i = 0; i < g.getNumGeometries(); i++) { Polygon poly = (Polygon) g.getGeometryN(i); polys.add(removeCoordinates(poly)); } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys)); }
/** * Computes a {@link Geometry} containing only {@link Polygonal} components. * Extracts the {@link Polygon}s from the input * and returns them as an appropriate {@link Polygonal} geometry. * <p> * If the input is already <tt>Polygonal</tt>, it is returned unchanged. * <p> * A particular use case is to filter out non-polygonal components * returned from an overlay operation. * * @param g the geometry to filter * @return a Polygonal geometry */ private static Geometry restrictToPolygons(Geometry g) { if (g instanceof Polygonal) { return g; } List polygons = PolygonExtracter.getPolygons(g); if (polygons.size() == 1) return (Polygon) polygons.get(0); return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons)); } }
/** * Removes duplicated coordinates within a MultiPolygon. * * @param multiPolygon * @param tolerance to delete the coordinates * @return * @throws java.sql.SQLException */ public static MultiPolygon removeDuplicateCoordinates(MultiPolygon multiPolygon, double tolerance) throws SQLException { ArrayList<Polygon> polys = new ArrayList<Polygon>(); for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { Polygon poly = (Polygon) multiPolygon.getGeometryN(i); polys.add(removeDuplicateCoordinates(poly, tolerance)); } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys)); }
/** * Removes duplicated coordinates within a MultiPolygon. * * @param multiPolygon * @param tolerance to delete the coordinates * @return * @throws java.sql.SQLException */ public static MultiPolygon removeDuplicateCoordinates(MultiPolygon multiPolygon, double tolerance) throws SQLException { ArrayList<Polygon> polys = new ArrayList<Polygon>(); for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { Polygon poly = (Polygon) multiPolygon.getGeometryN(i); polys.add(removeDuplicateCoordinates(poly, tolerance)); } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys)); }
private Geometry removeSmallHoles(Geometry inputPolygon, double areaTolerance) { Class<?> geomBinding = inputPolygon.getClass(); Geometry finalGeom = inputPolygon; if (Polygon.class.equals(geomBinding)) { finalGeom = removeSmallHoles((Polygon) inputPolygon, areaTolerance); } else if (MultiPolygon.class.equals(geomBinding)) { List<Polygon> polygons = new ArrayList<Polygon>(); for (int index = 0; index < inputPolygon.getNumGeometries(); index++) { Polygon polygon = (Polygon) inputPolygon.getGeometryN(index); polygons.add((Polygon) removeSmallHoles(polygon, areaTolerance)); } finalGeom = inputPolygon.getFactory().createMultiPolygon( GeometryFactory.toPolygonArray(polygons)); } finalGeom.setUserData(inputPolygon.getUserData()); return finalGeom; }
private Geometry removeHoles(Geometry inputPolygon) { Class<?> geomBinding = inputPolygon.getClass(); Geometry finalGeom = inputPolygon; if (Polygon.class.equals(geomBinding)) { finalGeom = removeHoles((Polygon) inputPolygon); } else if (MultiPolygon.class.equals(geomBinding)) { List<Polygon> polygons = new ArrayList<Polygon>(); for (int index = 0; index < inputPolygon.getNumGeometries(); index++) { Polygon polygon = (Polygon) inputPolygon.getGeometryN(index); polygons.add((Polygon) removeHoles(polygon)); } finalGeom = inputPolygon.getFactory().createMultiPolygon( GeometryFactory.toPolygonArray(polygons)); } finalGeom.setUserData(inputPolygon.getUserData()); return finalGeom; }
private Geometry removeHoles(Geometry inputPolygon) { Class<?> geomBinding = inputPolygon.getClass(); Geometry finalGeom = inputPolygon; if (Polygon.class.equals(geomBinding)) { finalGeom = removeHoles((Polygon) inputPolygon); } else if (MultiPolygon.class.equals(geomBinding)) { List<Polygon> polygons = new ArrayList<Polygon>(); for (int index = 0; index < inputPolygon.getNumGeometries(); index++) { Polygon polygon = (Polygon) inputPolygon.getGeometryN(index); polygons.add((Polygon) removeHoles(polygon)); } finalGeom = inputPolygon.getFactory().createMultiPolygon( GeometryFactory.toPolygonArray(polygons)); } finalGeom.setUserData(inputPolygon.getUserData()); return finalGeom; }
/** * Creates a GeometryCollection containing possible polygons formed * from the constituent linework of a set of geometries. * * @param geometry * @return */ public static Geometry polygonize(Geometry geometry) { if(geometry == null){ return null; } Polygonizer polygonizer = new Polygonizer(); polygonizer.add(geometry); Collection pols = polygonizer.getPolygons(); if(pols.isEmpty()){ return null; } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(pols)); } }
/** * Creates a GeometryCollection containing possible polygons formed * from the constituent linework of a set of geometries. * * @param geometry * @return */ public static Geometry polygonize(Geometry geometry) { if(geometry == null){ return null; } Polygonizer polygonizer = new Polygonizer(); polygonizer.add(geometry); Collection pols = polygonizer.getPolygons(); if(pols.isEmpty()){ return null; } return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(pols)); } }
/** * Create MultiPolygon as encoded by elemInfo. * * @param oraGeom SDO_GEOMETRY attributes being read * @param coords the coordinates of the entire geometry * @return MultiPolygon */ private MultiPolygon readMultiPolygon(OraGeom oraGeom) { int nElem = oraGeom.numElements(); List geoms = new ArrayList(); for (int i = 0; i < nElem; i++) { int etype = oraGeom.eType(i); if ((etype == OraGeom.ETYPE.POLYGON) || (etype == OraGeom.ETYPE.POLYGON_EXTERIOR)) { Polygon poly = readPolygon(oraGeom, i); i += poly.getNumInteriorRing(); // skip interior rings geoms.add(poly); } else { // not a Polygon - stop reading break; } } MultiPolygon polys = geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(geoms)); return polys; }
private Geometry removeSmallParts(Geometry polygon, double areaTolerance) { Class<?> geomBinding = polygon.getClass(); if (Polygon.class.equals(geomBinding)) { return polygon; } else if (MultiPolygon.class.equals(geomBinding)) { List<Polygon> remains = new ArrayList<Polygon>(); Geometry largest = polygon.getGeometryN(0); for (int index = 0; index < polygon.getNumGeometries(); index++) { Geometry part = polygon.getGeometryN(index); double area = part.getArea(); if (area > largest.getArea()) { largest = part; } if (area >= areaTolerance) { remains.add((Polygon) part); } } if (remains.size() == 0) { remains.add((Polygon) largest); } // return multipolygon Geometry parts = polygon.getFactory().createMultiPolygon( GeometryFactory.toPolygonArray(remains)); parts.setUserData(polygon.getUserData()); return parts; } else { return polygon; } } }
if (isCollection) { if (geom0 instanceof Polygon) { return createMultiPolygon(toPolygonArray(geomList));
Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries); MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray); multiPolygon.setUserData( getSRS() );
Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries); MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray); multiPolygon.setUserData( getSRS() );
MultiLineString voronoiSegs = geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()])); polygonizer.add(voronoiSegs); return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(polygonizer.getPolygons()));
MultiLineString voronoiSegs = geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()])); polygonizer.add(voronoiSegs); return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(polygonizer.getPolygons()));