Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries); MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray); multiPolygon.setUserData(getSRS());
@DescribeProcess( title = "Polygonize", description = "Creates a set of polygons from linestrings delineating them. The linestrings must be correctly noded (i.e. touch only at endpoints)." ) @DescribeResult(description = "The collection of created polygons") public static Geometry polygonize( @DescribeParameter(name = "geom", description = "Linework to polygonize") Geometry geom) { @SuppressWarnings("rawtypes") List lines = LineStringExtracter.getLines(geom); Polygonizer polygonizer = new Polygonizer(); polygonizer.add(lines); @SuppressWarnings("rawtypes") Collection polys = polygonizer.getPolygons(); Polygon[] polyArray = GeometryFactory.toPolygonArray(polys); return geom.getFactory().createGeometryCollection(polyArray); }
private MultiPolygon clean(MultiPolygon g) { List polys = new ArrayList(); for (int i = 0; i < g.getNumGeometries(); i++) { Polygon poly = (Polygon) g.getGeometryN(i); polys.add(clean(poly)); } return fact.createMultiPolygon(GeometryFactory.toPolygonArray(polys)); } private MultiLineString clean(MultiLineString g)
public Geometry createCollection(Geometry[] geometries) { return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray( Arrays.asList(geometries))); } };
/** * 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)); }
/** * 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)); } }
public static Geometry toMultiPolygon(Geometry g1, Geometry g2) { Geometry geoms = FunctionsUtil.buildGeometry(g1, g2); List polys = PolygonExtracter.getPolygons(g1); PolygonExtracter.getPolygons(g2, polys); return FunctionsUtil.getFactoryOrDefault(g1, g2) .createMultiPolygon( GeometryFactory.toPolygonArray(polys)); }
geometry = gf.createMultiPolygon(GeometryFactory.toPolygonArray(polygons));
if (isCollection) { if (geom0 instanceof Polygon) { return createMultiPolygon(toPolygonArray(geomList));
MultiLineString voronoiSegs = geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[0])); polygonizer.add(voronoiSegs); return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(polygonizer.getPolygons()));
public static Geometry overlaySnapRounded(Geometry g1, Geometry g2, double precisionTol) { PrecisionModel pm = new PrecisionModel(precisionTol); GeometryFactory geomFact = g1.getFactory(); List lines = LinearComponentExtracter.getLines(g1); // add second input's linework, if any if (g2 != null) LinearComponentExtracter.getLines(g2, lines); List nodedLinework = new GeometryNoder(pm).node(lines); // union the noded linework to remove duplicates Geometry nodedDedupedLinework = geomFact.buildGeometry(nodedLinework).union(); // polygonize the result Polygonizer polygonizer = new Polygonizer(); polygonizer.add(nodedDedupedLinework); Collection polys = polygonizer.getPolygons(); // convert to collection for return Polygon[] polyArray = GeometryFactory.toPolygonArray(polys); return geomFact.createGeometryCollection(polyArray); }