Skip to content
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

Fix empty bbox because of empty shapely_annotation.multipolygon #1140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vinnik-dmitry07
Copy link

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.

image

@fcakyon fcakyon requested a review from Copilot March 24, 2025 01:53
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines +41 to +44
polygons = [
geom.geoms if isinstance(geom, MultiPolygon) else geom
for geom in geometry.geoms if isinstance(geom, (Polygon, MultiPolygon))
]
Copy link
Preview

Copilot AI Mar 24, 2025

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.

Suggested change
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 is powered by AI, so mistakes are possible. Review output carefully before use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant