[Fix] Use poly_intersection instead of poly.intersection to avoid supurious warnings (#1811)

pull/1820/head
Tong Gao 2023-03-28 16:20:50 +08:00 committed by GitHub
parent 4b887676a3
commit 6342ff262c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -156,11 +156,9 @@ def crop_polygon(polygon: ArrayLike,
"""
poly = poly_make_valid(poly2shapely(polygon))
crop_poly = poly_make_valid(poly2shapely(bbox2poly(crop_box)))
poly_cropped = poly.intersection(crop_poly)
if poly_cropped.area == 0. or not isinstance(
area, poly_cropped = poly_intersection(poly, crop_poly, return_poly=True)
if area == 0 or area is None or not isinstance(
poly_cropped, shapely.geometry.polygon.Polygon):
# If polygon is outside crop_box region or the intersection is not a
# polygon, return None.
return None
else:
poly_cropped = poly_make_valid(poly_cropped)