Created
February 12, 2014 19:25
-
-
Save thomersch/8962703 to your computer and use it in GitHub Desktop.
Convert lat/lon to tile number
This file contains hidden or 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
import math | |
def lat_lon_to_tile(lat_deg, lon_deg, zoom): | |
def sec(x): | |
return 1/math.cos(x) | |
lat_rad = math.radians(lat_deg) | |
n = 2**zoom | |
xtile = n * ((lon_deg + 180) / 360) | |
ytile = n * (1 - (math.log(math.tan(lat_rad) + sec(lat_rad)) / math.pi)) / 2 | |
return int(xtile), int(ytile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment