Skip to content

Commit

Permalink
Fix buffer without overlap (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet authored Nov 20, 2024
1 parent 676bf76 commit 049f39b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 049f39b

Please sign in to comment.