i am working on calculating tile bounds lat lon from x,y,z tile coordinate. i have looked gdal2tiles code structure and i have found this good function:

def TileLatLonBounds( tx, ty, zoom ):
"Returns bounds of the given tile in latutude/longitude using WGS84 datum"

bounds = TileBounds(tx, ty, zoom)
minLat, minLon = MetersToLatLon(bounds[0], bounds[1])
maxLat, maxLon = MetersToLatLon(bounds[2], bounds[3])

with this code and its dependies i am getting result of this for tms scheme:

1.TileLatLonBounds(0, 3, 2) # 66.51326044311185, -180.0, 85.0511287798066, -90.0
2.TileLatLonBounds(3, 0, 2) # -85.05112877980659, 89.99999999999999, -66.51326044311185, 180.0

but i know world extent is for upper left -180 90, for lower right is 180 -90. so for first function (minLat, minLon, maxLat, maxLon) maxLat must be 90 instead of 85.0511287798066 and for second function minlat must be -90 instead of -85.05112877980659.

if i want use gdal translate function for rectifying for an image which contains world extent, then web tiling it, and using with openlayers or anything like this i think there will be problem with click into place of its....

and when opening -180 90 180 -90 tif and -180 85.05112877980659 180 -85.05112877980659 tif with global mapper you can see the diffrence of coordinate...

ok. what is your opinion for fixing this problem? or is it not a problem for tiling with gdal2tiles

  • when i remove this "lat = 180 / math.pi * (2 * math.atan(math.exp(lat * math.pi / 180.0)) - math.pi / 2.0)" from MetersToLatLon( mx, my ) function, such as result may improved.. what is your opinion
    – urcm
    Feb 10, 2012 at 17:30
  • Up vote for the word "dependies"
    – Chris
    Apr 22, 2021 at 12:49

1 Answer 1


Read up on Web Mercator. Tiles go to -Infinity at -90, not 0, and that's why the gdal2tiles code works the way it does.

  • ok. now i will commenting above code and i think this will take me the right way...
    – urcm
    Feb 11, 2012 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.