Skip to content

Instantly share code, notes, and snippets.

@sepulchered
Last active March 18, 2023 13:52
Show Gist options
  • Save sepulchered/6714835 to your computer and use it in GitHub Desktop.
Save sepulchered/6714835 to your computer and use it in GitHub Desktop.
Python code to convert from EPSG:4326 to EPSG:900913 and vice versa
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
@czambrano97
Copy link

Thx for the convertion, it's really work for geoengine aplication to calculate extent of map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment