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

REGR: fallback oriented_envelope does not work with GeoSeries #1929

Closed
martinfleis opened this issue Oct 31, 2023 · 1 comment · Fixed by #1939
Closed

REGR: fallback oriented_envelope does not work with GeoSeries #1929

martinfleis opened this issue Oct 31, 2023 · 1 comment · Fixed by #1939
Labels

Comments

@martinfleis
Copy link
Contributor

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants