Skip to content

Instantly share code, notes, and snippets.

@koorukuroo
Forked from sepulchered/epsg_4326_900913
Last active August 29, 2015 14:17
Show Gist options
  • Save koorukuroo/1c2ce363a0b918f9c0a6 to your computer and use it in GitHub Desktop.
Save koorukuroo/1c2ce363a0b918f9c0a6 to your computer and use it in GitHub Desktop.
def epsg_4326_to_900913(lon, lat):
x = lon * 20037508.34 / 180
y = (math.log(math.tan((90 + lat) * math.pi / 360)) / (math.pi / 180)) * (20037508.34 / 180)
return x, y
def epsg_900913_to_4326(x, y):
lon = x * 180 / 20037508.34
lat = (360 / math.pi) * math.atan(math.exp(y * math.pi / 20037508.34)) - 90
return lon, lat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment