-
Notifications
You must be signed in to change notification settings - Fork 611
REGR: fallback oriented_envelope does not work with GeoSeries #1929
Copy link
Copy link
Closed
Labels
Description
Expected behavior and actual behavior.
When shapely 2.0.2 falls back to the _oriented_envelope_min_area algorithm when older GEOS is present, shapely.oriented_envelope fails when a GeoSeries is given.
Steps to reproduce the problem.
>>> import shapely
>>> import geopandas as gpd
>>> gs = gpd.GeoSeries([shapely.Point(0, 0).buffer(1), shapely.Point(90, 0).buffer(1)])
>>> shapely.oriented_envelope(gs)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/martin/miniforge3/envs/shapely_debug/lib/python3.12/site-packages/shapely/constructive.py", line 1034, in oriented_envelope
return f(geometry, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/martin/miniforge3/envs/shapely_debug/lib/python3.12/site-packages/shapely/algorithms/_oriented_envelope.py", line 22, in _oriented_envelope_min_area
if geometry.is_empty:
^^^^^^^^^^^^^^^^^
File "/Users/martin/miniforge3/envs/shapely_debug/lib/python3.12/site-packages/pandas/core/generic.py", line 1519, in __nonzero__
raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().We need to pass a GeoSeries here but since it has a geom_type attribute, it is send to geometry.is_empty which fails.
shapely/shapely/algorithms/_oriented_envelope.py
Lines 20 to 23 in 9540b77
| if not hasattr(geometry, "geom_type"): | |
| return np.array([_oriented_envelope_min_area(g) for g in geometry]) | |
| if geometry.is_empty: | |
| return shapely.from_wkt("POLYGON EMPTY") |
I suppose that replacing not hasattr(geometry, "geom_type") with some more generic check for array-like would fix it. Maybe check for "len"?
Operating system
All of them
Shapely version and provenance
Shapely 2.0.2 with GEOS < 3.12.
Reactions are currently unavailable