Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around GEOS issue in voronoi_frames #693

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion libpysal/cg/voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def voronoi_frames(
"Use 'GeoSeries.to_crs()' to re-project geometries to a "
"projected CRS before using voronoi_polygons.",
)

# Set precision of the input geometry (avoids GEOS precision issues)
objects = shapely.set_precision(geometry.geometry.copy(), grid_size)

Expand Down Expand Up @@ -429,7 +430,15 @@ def voronoi_frames(
shapely.GeometryCollection(objects.values), extend_to=limit
)
# Get individual polygons out of the collection
polygons = gpd.GeoSeries(shapely.get_parts(voronoi), crs=geometry.crs)
polygons = gpd.GeoSeries(
shapely.make_valid(shapely.get_parts(voronoi)), crs=geometry.crs
)

# temporary fix for libgeos/geos#1062
if not (polygons.geom_type == "Polygon").all():
polygons = polygons.explode(ignore_index=True)
polygons = polygons[polygons.geom_type == "Polygon"]

# Assign to each input geometry the corresponding Voronoi polygon
# TODO: check if we still need indexing after shapely/shapely#1968 is released
if GPD_GE_013:
Expand Down
Loading