home
#!/usr/bin/python
#
# The mercator projection
#
# http://mathworld.wolfram.com/MercatorProjection.html
#
import math
def getMercatorYfromLatitude(lat):
lat = float(lat)
if (lat > 90) : lat = lat - 180
if (lat < -90) : lat = lat + 180
phi = math.radians(lat)
y = 0.5 * math.log( (1.0 + math.sin(phi)) / (1.0 - math.sin(phi)) )
return y
# maxlat = math.pi
# maxTileY = math.pow(2, zoom)
# result = int( 0.5 * (1 - y / maxlat) * (maxTileY) )
# return (result);
def getLatitudeFromMercatorY(mercatorY):
phi = ( 2.0 * math.atan ( math.exp(mercatorY) ) ) - ( 0.5 * math.pi)
lat = math.degrees(phi)
return (lat)
if __name__ == "__main__":
c0 = 43.1742630005
m = getMercatorYfromLatitude(c0)
c = getLatitudeFromMercatorY(m)
print c0
print m
print c