Skip to content

Instantly share code, notes, and snippets.

@sgraaf
Created October 27, 2020 12:33
Show Gist options
  • Save sgraaf/41a4189c8832f0856c6e1c6269ecb5f5 to your computer and use it in GitHub Desktop.
Save sgraaf/41a4189c8832f0856c6e1c6269ecb5f5 to your computer and use it in GitHub Desktop.
Convert a Quadkey to Tile (XY) coordinates (see: https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system)
from typing import Tuple
def quadkey_to_xy(quadkey: str) -> Tuple[int, int]:
x, y = (0, 0)
level = len(quadkey)
for i in range(level):
bit = level - i
mask = 1 << (bit - 1)
if quadkey[level - bit] == '1':
x |= mask
if quadkey[level - bit] == '2':
y |= mask
if quadkey[level - bit] == '3':
x |= mask
y |= mask
return x, y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment