Created
October 27, 2020 12:33
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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