Skip to content

Commit 08e4b9f

Browse files
committed
Fix an edge case where geometry maybe invalid after clipping
1 parent d836c86 commit 08e4b9f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

wsidata/_accessors/iter.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,11 @@ def tile_images(
369369
cv2.fillPoly(anno_mask, [cnt], int(label)) # noqa
370370
cv2.fillPoly(anno_mask, holes, 0) # noqa
371371
# Clip the annotation by the tile
372+
# May not be valid after clipping
372373
output_geo = clip_by_rect(geo, 0, 0, *mask_size)
373-
if isinstance(output_geo, MultiPolygon):
374+
if not output_geo.is_valid:
375+
continue
376+
elif isinstance(output_geo, MultiPolygon):
374377
output_geo = [p for p in output_geo.geoms]
375378
else:
376379
output_geo = [output_geo]

0 commit comments

Comments
 (0)