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

Return a 1x1 image when bbox is smaller than a single pixel #637

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

JackDunnNZ
Copy link
Contributor

This was originally motivated by hitting a zero-division error when calling Reader.feature with a feature that happened to be smaller than one pixel in the image:

File "site-packages/rasterio/transform.py", line 189, in from_bounds
    (east - west) / width, (south - north) / height)
    ~~~~~~~~~~~~^~~~~~~~~
ZeroDivisionError: float division by zero

I traced it back to the result of part being a 0x0 image when the bbox was smaller than a single pixel of the image, which this change fixes and returns a 1x1 image instead.

I'm not 100% sure about this, but it seems to make sense to me that part returning a single pixel is the correct outcome for this case, as this is still the valid image data for the bbox being requested.

Copy link
Member

@vincentsarago vincentsarago left a comment

Choose a reason for hiding this comment

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

🙏 that totally makes senses

thank you

@vincentsarago vincentsarago merged commit a272374 into cogeotiff:main Sep 13, 2023
6 checks passed
@JackDunnNZ JackDunnNZ deleted the jd/smallbbox branch September 13, 2023 19:39
@JackDunnNZ
Copy link
Contributor Author

Thanks!

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.

2 participants