Skip to content

Instantly share code, notes, and snippets.

View czambrano97's full-sized avatar

Ceider czambrano97

  • Santo Domingo, Ecuador
View GitHub Profile
@sepulchered
sepulchered / epsg_4326_900913
Last active March 18, 2023 13:52
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