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 "Tile index out of bounds" error for very north tiles #184

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

danscales
Copy link
Contributor

Fix "Tile index out of bounds" error for very north tiles for dynamic tile access

We are hitting the edges of the whole-world bounding box for very north tiles, and need to add some rounding to deal with slight imprecision in the floating point computations.

We are hitting the edges of the whole-world bounding box for very north
tiles, and need to add some rounding to deal with slight imprecision in
the floating point computations.
Copy link
Member

@jterry64 jterry64 left a comment

Choose a reason for hiding this comment

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

This looks right, but maybe you can quickly confirm that round(right, 0) > round(max_right, 0) gives the right answer for the numbers we were looking at in your python console?

@danscales
Copy link
Contributor Author

This looks right, but maybe you can quickly confirm that round(right, 0) > round(max_right, 0) gives the right answer for the numbers we were looking at in your python console?

Yes, here is the output, where we get True without rounding (which leads to the error) and False after rounding (because right and max_right become equal):

Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mercantile
>>> mercantile.xy_bounds(0, 0, 0)
Bbox(left=-20037508.342789244, bottom=-20037508.342789244, right=20037508.342789244, top=20037508.342789244)
>>> mercantile.xy_bounds(7, 2, 3)
Bbox(left=15028131.257091936, bottom=5009377.085697311, right=20037508.342789248, top=10018754.171394622)
>>> 20037508.342789248 > 20037508.342789244
True
>>> round(20037508.342789248, 0) > round(20037508.342789244, 0)
False
>>> 

@danscales danscales merged commit d894a17 into staging Dec 12, 2024
5 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.

2 participants