After upgrading to shapely 2.0, when I am trying to get the optimized alpha from a set of points, I encounter the following error:
Traceback (most recent call last):
File "/home/hanatok/HDD/Documents/playground/python/test_alphashape/./test.py", line 5, in <module>
alpha = 0.95 * alphashape.optimizealpha(points)
File "/home/hanatok/mambaforge/lib/python3.10/site-packages/alphashape/optimizealpha.py", line 100, in optimizealpha
if _testalpha(points, test_alpha):
File "/home/hanatok/mambaforge/lib/python3.10/site-packages/alphashape/optimizealpha.py", line 41, in _testalpha
return all([polygon.intersects(point) for point in points])
TypeError: 'MultiPoint' object is not iterable
After debugging I have found that the issue is related to the changes in shapely 2.0. If I apply the following patch:
diff --git a/alphashape/optimizealpha.py b/alphashape/optimizealpha.py
index 6c0b72f..a3391c2 100644
--- a/alphashape/optimizealpha.py
+++ b/alphashape/optimizealpha.py
@@ -37,7 +37,7 @@ def _testalpha(points: Union[List[Tuple[float]], np.ndarray], alpha: float):
polygon = alphashape(points, alpha)
if isinstance(polygon, shapely.geometry.polygon.Polygon):
if not isinstance(points, MultiPoint):
- points = MultiPoint(list(points))
+ points = MultiPoint(list(points)).geoms
return all([polygon.intersects(point) for point in points])
elif isinstance(polygon, trimesh.base.Trimesh):
return len(polygon.faces) > 0 and all(
Description
After upgrading to shapely 2.0, when I am trying to get the optimized alpha from a set of points, I encounter the following error:
After debugging I have found that the issue is related to the changes in shapely 2.0. If I apply the following patch:
then it works as expected.
What I Did
The traceback is attached above.
What I Expected
The above code runs without throwing the traceback.
Acceptance Criteria
No runtime exceptions.