/** * 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 static void main(String[] args) { GeometryFactory geometryFactory = new GeometryFactory(); Collection<Coordinate> sites = new ArrayList<>(); sites.add(new Coordinate(70, 70)); sites.add(new Coordinate(50, 150)); sites.add(new Coordinate(150, 50)); sites.add(new Coordinate(150, 150)); sites.add(new Coordinate(250, 50)); sites.add(new Coordinate(250, 150)); sites.add(new Coordinate(350, 50)); sites.add(new Coordinate(370, 170)); VoronoiDiagramBuilder voronoiDiagramBuilder = new VoronoiDiagramBuilder(); voronoiDiagramBuilder.setSites(sites); List<Polygon> polygons = voronoiDiagramBuilder.getSubdivision().getVoronoiCellPolygons(geometryFactory); BoundingBox boundingBox = BoundingBox.createBoundingBox(0, 0, 400, 200); Polygon boundingPolygon = VoronoiGeometryUtils.createBoundingPolygon(boundingBox); Collection<Geometry> cutGeometries = VoronoiGeometryUtils.cutPolygonsByBoundary(polygons, boundingPolygon); Collection<SimpleFeature> features = VoronoiGeometryUtils.createFeaturesFromPolygons(cutGeometries); ShapeFileWriter.writeGeometries(features, "/Users/dominik/voronoi_test.shp"); } }
/** * 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)); }
static Collection<Geometry> determineVoronoiShapes(ActivityFacilities measuringPoints, BoundingBox box) { LOG.warn("Started creating Voronoi shapes."); Collection<Coordinate> sites = new ArrayList<>(); for (ActivityFacility measuringPoint : measuringPoints.getFacilities().values()) { Coordinate coordinate = new Coordinate(measuringPoint.getCoord().getX(), measuringPoint.getCoord().getY()); sites.add(coordinate); } VoronoiDiagramBuilder voronoiDiagramBuilder = new VoronoiDiagramBuilder(); voronoiDiagramBuilder.setSites(sites); List<Polygon> polygons = voronoiDiagramBuilder.getSubdivision().getVoronoiCellPolygons(geometryFactory); Polygon boundingPolygon = createBoundingPolygon(box); Collection<Geometry> geometries = cutPolygonsByBoundary(polygons, boundingPolygon); LOG.warn("Finished creating Voronoi shapes."); return geometries; }
@SuppressWarnings("unchecked") Collection<Polygon> cityVoronoiPolygons = subdivision.getVoronoiCellPolygons(fatory);