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

Don't allow creating tiles with negative zoom levels. #141

Open
geospatial-jeff opened this issue Jul 19, 2021 · 0 comments
Open

Don't allow creating tiles with negative zoom levels. #141

geospatial-jeff opened this issue Jul 19, 2021 · 0 comments

Comments

@geospatial-jeff
Copy link

geospatial-jeff commented Jul 19, 2021

This was first brought up in #122 (comment) which mentions the use case of calculating the parent of a zoom 0 tile:

>>> mercantile.parent(mercantile.Tile(0,0,0))
Tile(x=0, y=0, z=-1)

The zoom 0 parent tile case was fixed in #130, the changelog entry from that PR says:

The Tile constructor in mercantile 2.0 will refuse to make tiles with X and Y
indexes outside of the range 0 <= value <= 2 ** zoom. It will also require
indexes to be integers.

But this constraint actually isn't true, here is a really easy way to break it:

import mercantile

zoom = -1
min_index = 0
max_index = 2 ** zoom

tile = mercantile.Tile(x=10, y=10, z=zoom)
assert min_index <= tile.x <= max_index # raises AssertionError
assert min_index <= tile.y <= max_index # raises AssertionError

The easiest way to make the aforementioned constraint actually work is to prevent users from creating tiles with a negative zoom level, and in my opinion this is really what the constraint is trying to do. Mercantile is a library for Spherical mercator coordinate and tile utilities. By definition the lowest zoom level in the mercator grid is zoom 0, at which point a single tile covers the the entire world. So even allowing users to provide a negative zoom seems to break the original intention of the library, and can lead to some very unintuitive behavior that doesn't align with how the mercator grid works in reality:

tile = mercantile.Tile(x=0, y=0, z=-1)
children = mercantile.children(tile)

# Mercator grid by definition only has a single Z0 tile
assert len(children) == 4
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

No branches or pull requests

1 participant