# Converting x, y, zoom for Calculating tile bounds

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 Feb 10, 2012 at 17:30
• Up vote for the word "dependies" Apr 22, 2021 at 12:49