/** * Gets the cells in the Voronoi diagram for this triangulation. * The cells are returned as a {@link GeometryCollection} of {@link Polygon}s * <p> * The userData of each polygon is set to be the {@link Coordinate} * of the cell site. This allows easily associating external * data associated with the sites to the cells. * * @param geomFact a geometry factory * @return a GeometryCollection of Polygons */ public Geometry getVoronoiDiagram(GeometryFactory geomFact) { List vorCells = getVoronoiCellPolygons(geomFact); return geomFact.createGeometryCollection(GeometryFactory.toGeometryArray(vorCells)); }
public GeometryCollection map(GeometryCollection gc) { List mapped = new ArrayList(); for (int i = 0; i < gc.getNumGeometries(); i++) { Geometry g = mapOp.map(gc.getGeometryN(i)); if (!g.isEmpty()) mapped.add(g); } return gc.getFactory().createGeometryCollection( GeometryFactory.toGeometryArray(mapped)); } }
protected Geometry transformGeometryCollection(GeometryCollection geom, Geometry parent) { List transGeomList = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry transformGeom = transform(geom.getGeometryN(i)); if (transformGeom == null) continue; if (pruneEmptyGeometry && transformGeom.isEmpty()) continue; transGeomList.add(transformGeom); } if (preserveGeometryCollectionType) return factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)); return factory.buildGeometry(transGeomList); }
return createGeometryCollection(toGeometryArray(geomList));
private static Geometry clipGeometryCollection(Geometry geom, Envelope clipEnv) { Geometry clipPoly = geom.getFactory().toGeometry(clipEnv); List clipped = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry g = geom.getGeometryN(i); Geometry result = null; // don't clip unless necessary if (clipEnv.contains(g.getEnvelopeInternal())) result = g; else if (clipEnv.intersects(g.getEnvelopeInternal())) { result = clipPoly.intersection(g); // keep vertex key info result.setUserData(g.getUserData()); } if (result != null && ! result.isEmpty()) { clipped.add(result); } } return geom.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(clipped)); } }
private static GeometryCollection componentBuffers(Geometry g, double distance) { List<Geometry> bufs = new ArrayList<Geometry>(); for (Iterator it = new GeometryCollectionIterator(g); it.hasNext();) { Geometry comp = (Geometry) it.next(); if (comp instanceof GeometryCollection) continue; bufs.add(comp.buffer(distance)); } return GEOMETRY_FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(bufs)); }
private static GeometryCollection componentBuffers(Geometry g, double distance) { List<Geometry> bufs = new ArrayList<Geometry>(); for (Iterator it = new GeometryCollectionIterator(g); it.hasNext();) { Geometry comp = (Geometry) it.next(); if (comp instanceof GeometryCollection) continue; bufs.add(comp.buffer(distance)); } return GEOMETRY_FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(bufs)); }
/** * Gets the cells in the Voronoi diagram for this triangulation. * The cells are returned as a {@link GeometryCollection} of {@link Polygon}s * <p> * The userData of each polygon is set to be the {@link Coordinate} * of the cell site. This allows easily associating external * data associated with the sites to the cells. * * @param geomFact a geometry factory * @return a GeometryCollection of Polygons */ public Geometry getVoronoiDiagram(GeometryFactory geomFact) { List vorCells = getVoronoiCellPolygons(geomFact); return geomFact.createGeometryCollection(GeometryFactory.toGeometryArray(vorCells)); }
/** * Removes duplicated coordinates within a GeometryCollection * @param g * @return */ public static GeometryCollection removeDuplicateCoordinates(GeometryCollection g) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); for (int i = 0; i < g.getNumGeometries(); i++) { Geometry geom = g.getGeometryN(i); geoms.add(removeDuplicateCoordinates(geom)); } return FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(geoms)); }
/** * Gets a geometry representing the polygons formed by the polygonization. * If a valid polygonal geometry was extracted the result is a {@linkl Polygonal} geometry. * * @return a geometry containing the polygons */ public Geometry getGeometry() { if (geomFactory == null) geomFactory = new GeometryFactory(); polygonize(); if (extractOnlyPolygonal) { return geomFactory.buildGeometry(polyList); } // result may not be valid Polygonal, so return as a GeometryCollection return geomFactory.createGeometryCollection(GeometryFactory.toGeometryArray(polyList)); }
/** * Removes duplicated coordinates within a GeometryCollection * * @param g * @return */ public static GeometryCollection removeCoordinates(GeometryCollection g) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); for (int i = 0; i < g.getNumGeometries(); i++) { Geometry geom = g.getGeometryN(i); geoms.add(removeCoordinates(geom)); } return FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(geoms)); } }
/** * Removes duplicated coordinates within a GeometryCollection * * @param g * @return */ public static GeometryCollection removeCoordinates(GeometryCollection g) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); for (int i = 0; i < g.getNumGeometries(); i++) { Geometry geom = g.getGeometryN(i); geoms.add(removeCoordinates(geom)); } return FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(geoms)); } }
/** * Removes duplicated coordinates within a GeometryCollection * * @param geometryCollection * @param tolerance to delete the coordinates * @return * @throws java.sql.SQLException */ public static GeometryCollection removeDuplicateCoordinates(GeometryCollection geometryCollection, double tolerance) throws SQLException { ArrayList<Geometry> geoms = new ArrayList<>(); for (int i = 0; i < geometryCollection.getNumGeometries(); i++) { Geometry geom = geometryCollection.getGeometryN(i); geoms.add(removeDuplicateCoordinates(geom, tolerance)); } return FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(geoms)); } }
/** * Removes duplicated coordinates within a GeometryCollection * * @param geometryCollection * @param tolerance to delete the coordinates * @return * @throws java.sql.SQLException */ public static GeometryCollection removeDuplicateCoordinates(GeometryCollection geometryCollection, double tolerance) throws SQLException { ArrayList<Geometry> geoms = new ArrayList<>(); for (int i = 0; i < geometryCollection.getNumGeometries(); i++) { Geometry geom = geometryCollection.getGeometryN(i); geoms.add(removeDuplicateCoordinates(geom, tolerance)); } return FACTORY.createGeometryCollection(GeometryFactory.toGeometryArray(geoms)); } }
/** * Helper method for {@link #intersection(Geometry, Geometry) intersection(Geometry, Geometry)} */ private static GeometryCollection intersection(GeometryCollection gc1, GeometryCollection gc2) { List<Geometry> ret = new ArrayList<Geometry>(); final int size=gc1.getNumGeometries(); for (int i = 0; i < size; i++) { Geometry g1 = (Geometry)gc1.getGeometryN(i); List<Geometry> partial = intersection(gc2, g1); ret.addAll(partial); } return gc1.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(ret)); }
public GeometryCollection map(GeometryCollection gc) { List mapped = new ArrayList(); for (int i = 0; i < gc.getNumGeometries(); i++) { Geometry g = mapOp.map(gc.getGeometryN(i)); if (!g.isEmpty()) mapped.add(g); } return gc.getFactory().createGeometryCollection( GeometryFactory.toGeometryArray(mapped)); } }
protected Geometry transformGeometryCollection(GeometryCollection geom, Geometry parent) { List transGeomList = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry transformGeom = transform(geom.getGeometryN(i)); if (transformGeom == null) continue; if (pruneEmptyGeometry && transformGeom.isEmpty()) continue; transGeomList.add(transformGeom); } if (preserveGeometryCollectionType) return factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)); return factory.buildGeometry(transGeomList); }
/** * Return the intersection of two Geometries. * <BR>This method relies completely on {@link Geometry#intersection(Geometry)} * but also tries to unroll <TT>GeometryCollection</TT>s. * * @param g1 * @param g2 * @return true if the two geometries intersect. */ public static Geometry intersection(Geometry g1, Geometry g2) { if(g1 instanceof GeometryCollection) { if(g2 instanceof GeometryCollection) { return intersection((GeometryCollection)g1, (GeometryCollection)g2); } else { List<Geometry> ret = intersection((GeometryCollection)g1, g2); return g1.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(ret)); } } else { if(g2 instanceof GeometryCollection) { List<Geometry> ret = intersection((GeometryCollection)g2, g1); return g1.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(ret)); } else { return g1.intersection(g2); } } }
continue; Geometry[] geometries = GeometryFactory.toGeometryArray(entry.getValue()); GeometryCollection geomCol = gf.createGeometryCollection(geometries); Geometry circle = new MinimumBoundingCircle(geomCol).getCircle();
private static Geometry clipGeometryCollection(Geometry geom, Envelope clipEnv) { Geometry clipPoly = geom.getFactory().toGeometry(clipEnv); List clipped = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry g = geom.getGeometryN(i); Geometry result = null; // don't clip unless necessary if (clipEnv.contains(g.getEnvelopeInternal())) result = g; else if (clipEnv.intersects(g.getEnvelopeInternal())) { result = clipPoly.intersection(g); // keep vertex key info result.setUserData(g.getUserData()); } if (result != null && ! result.isEmpty()) { clipped.add(result); } } return geom.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(clipped)); } }