Last active
March 18, 2023 13:52
-
-
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
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
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
Thx for the convertion, it's really work for geoengine aplication to calculate extent of map.