Skip to content

REGR: fallback oriented_envelope does not work with GeoSeries #1929

@martinfleis

Description

@martinfleis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions