Skip to content

Support for multipolygons in zonal_statistics#428

Merged
emilyanndavis merged 3 commits intonatcap:mainfrom
emlys:bugfix/322
Apr 22, 2025
Merged

Support for multipolygons in zonal_statistics#428
emilyanndavis merged 3 commits intonatcap:mainfrom
emlys:bugfix/322

Conversation

@emlys
Copy link
Copy Markdown
Member

@emlys emlys commented Apr 8, 2025

Fixes #322

  • Check the input geometry type, and raise an error if it's not Polygon or MultiPolygon
  • When creating the temporary vector used in zonal_statistics, use the appropriate geometry type according to the input type (Polygon or MultiPolygon) to prevent the warnings seen sometimes in invest.

A PR in invest (natcap/invest#1882) goes along with this, but the order of merging doesn't matter.

layer.SyncToDisk()
layer = None
vector = None
_geometry_to_vector([geom], vector_path, projection_epsg=4326)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating a few unrelated tests to use _geometry_to_vector - better to avoid duplicating all the layer creation code, and it sets the geometry type correctly, which is now required.

@emlys emlys changed the title zonal_stats: support multipolygons Support for multipolygons in zonal_statistics Apr 8, 2025
@emlys emlys requested a review from emilyanndavis April 8, 2025 20:06
@emlys emlys self-assigned this Apr 8, 2025
@davemfish davemfish added this to the 2.4.8 milestone Apr 22, 2025
Copy link
Copy Markdown
Member

@emilyanndavis emilyanndavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @emlys! Looking forward to seeing fewer warnings in the InVEST logs. :)

@emilyanndavis emilyanndavis merged commit ab38aa5 into natcap:main Apr 22, 2025
63 checks passed
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.

Confirm and document whether or not zonal_statistics works for other geometries

3 participants