1
2 """Translates between lat/long and the slippy-map tile numbering scheme
3
4 http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames
5
6 @author: Oliver White
7 @date: 2007
8 @license: This file is public-domain.
9
10 """
11
12 __author__ = "Oliver White"
13 __copyright__ = "(c) 2007, Oliver White"
14 __license__ = "This file is public-domain."
15
16 from math import *
17
20
23
25 x = (lon + 180) / 360
26 y = (1 - log(tan(radians(lat)) + sec(radians(lat))) / pi) / 2
27 return(x, y)
28
33
37
44
53
55 n = numTiles(z)
56 unit = 360 / n
57 lon1 = -180 + x * unit
58 lon2 = lon1 + unit
59 return(lon1, lon2)
60
65
67 return(degrees(atan(sinh(mercatorY))))
68
71
73 if(layer in ('oam')):
74 return('jpg')
75 return('png')
76
78 layers = {"tah": "http://cassini.toolserver.org:8080/http://a.tile.openstreetmap.org/+http://toolserver.org/~cmarqu/hill/",
79
80 "oam": "http://oam1.hypercube.telascience.org/tiles/1.0.0/openaerialmap-900913/",
81 "mapnik": "http://tile.openstreetmap.org/mapnik/"
82 }
83 return(layers[layer])
84
87
88 if __name__ == "__main__":
89 for z in range(0,18):
90 x,y = tileXY(52.37930, 9.72310, z)
91
92 s,w,n,e = tileEdges(x,y,z)
93 print "%d: %d,%d --> %1.3f :: %1.3f, %1.3f :: %1.3f" % (z,x,y,s,n,w,e)
94
95