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

Fix buffer without overlap #630

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions geoutils/vector/geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def _buffer_metric(gdf: gpd.GeoDataFrame, buffer_size: float) -> gu.Vector:


def _buffer_without_overlap(
gdf: gpd.GeoDataFrame, buffer_size: int | float, metric: bool = True, plot: bool = False
ds: gpd.GeoDataFrame, buffer_size: int | float, metric: bool = True, plot: bool = False
) -> gu.Vector:
"""See Vector.buffer_without_overlap() for details."""

# Project in local UTM if metric is True
if metric:
crs_utm_ups = _get_utm_ups_crs(df=gdf)
gdf = gdf.to_crs(crs=crs_utm_ups)
crs_utm_ups = _get_utm_ups_crs(df=ds)
gdf = ds.to_crs(crs=crs_utm_ups)
else:
gdf = gdf
gdf = ds

# Dissolve all geometries into one
merged = gdf.dissolve()
Expand Down Expand Up @@ -111,7 +111,7 @@ def _buffer_without_overlap(

# Reverse-project to the original CRS if metric is True
if metric:
merged_voronoi = merged_voronoi.to_crs(crs=gdf.crs)
merged_voronoi = merged_voronoi.to_crs(crs=ds.crs)

return gu.Vector(merged_voronoi)

Expand Down
1 change: 1 addition & 0 deletions tests/test_vector/test_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def test_buffer_without_overlap(self, monkeypatch) -> None: # type: ignore
# Output should be of same size as input and same geometry type
assert len(buffer.ds) == len(two_squares.ds)
assert np.all(buffer.ds.geometry.geom_type == two_squares.ds.geometry.geom_type)
assert buffer.crs == two_squares.crs

# Extract individual geometries
polys = []
Expand Down
Loading