Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Extend rasterio.mask to accept ndarrays. #3274

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

groutr
Copy link
Contributor

@groutr groutr commented Dec 6, 2024

This addresses a very awkward usage of masking. Only datasets are accepted in the functions in rasterio.mask making it very awkward to mask raster data in passes. Most of the underlying functions in rasterio.features accept ndarrays as input with the exception of the important geometry_window function.

This PR updates geometry_window to accept either a dataset or ndarray + transform, consistent with the rest of the functions in that module. Now that geometry_window can accept ndarrays, the functions in rasterio.mask can now also easily support operating on ndarrays as well.

In my day job, we have a dataset that is masked in several passes. Currently, the code clumsily uses MemoryFile as the only viable/publicly supported way to satisfy the API of rasterio. This results in lots of excess code. Now, hopefully, the outputs of mask can be passed back in as inputs to mask.

@groutr
Copy link
Contributor Author

groutr commented Dec 6, 2024

Marked as draft because I think the code looks a little sloppy. @sgillies do you have any feedback on adding this ndarray support?

@groutr
Copy link
Contributor Author

groutr commented Mar 10, 2025

This will need updating after #3315 is potentially merged.

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