-
Notifications
You must be signed in to change notification settings - Fork 662
Fix empty bbox because of empty shapely_annotation.multipolygon #1140
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses an issue where an empty bounding box is produced due to handling of empty MultiPolygon annotations.
- Refactors the polygon filtering logic to accommodate both Polygon and MultiPolygon types found in geometry.geoms.
- Aims to prevent returning invalid or nested geometries when the collection contains MultiPolygon objects.
polygons = [ | ||
geom.geoms if isinstance(geom, MultiPolygon) else geom | ||
for geom in geometry.geoms if isinstance(geom, (Polygon, MultiPolygon)) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning 'geom.geoms' here may result in a nested list when constructing a MultiPolygon, as MultiPolygon expects a flat list of Polygon objects. Consider flattening the list by extending the collection of polygons for MultiPolygon objects.
polygons = [ | |
geom.geoms if isinstance(geom, MultiPolygon) else geom | |
for geom in geometry.geoms if isinstance(geom, (Polygon, MultiPolygon)) | |
] | |
polygons = [] | |
for geom in geometry.geoms: | |
if isinstance(geom, Polygon): | |
polygons.append(geom) | |
elif isinstance(geom, MultiPolygon): | |
polygons.extend(geom.geoms) |
Copilot uses AI. Check for mistakes.
Basically, the idea of this "if" section is to filter things like LineString from geometry.geoms but geometry.geoms can contain not only Polygon but MultiPolygon as well. Might be related to #1094, #1118, #1138.