Skip to content

Instantly share code, notes, and snippets.

@kuwapa
Last active April 24, 2022 14:26
Show Gist options
  • Save kuwapa/72c61355bf9d707abee5acc889959a5b to your computer and use it in GitHub Desktop.
Save kuwapa/72c61355bf9d707abee5acc889959a5b to your computer and use it in GitHub Desktop.
import math
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = int((lon_deg + 180.0) / 360.0 * n)
ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
return (xtile, ytile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment