Last active
June 8, 2022 13:24
-
-
Save wolfiex/c7603c71ebc966a8530bb0132977f6f5 to your computer and use it in GitHub Desktop.
Revisions
-
wolfiex revised this gist
Apr 2, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ def tile_translator(z,x,y,newzoom): def get_children(z,x,y): ''' Return the children of a tile ''' tile = list(map(int,(tile_translator(z,x,y,z+1).split('/')))) return [[tile[0],tile[1]+i,tile[2]+j] for i in [0,1] for j in [0,1]] -
wolfiex created this gist
Apr 2, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ ''' A collection of Tile tools in python. Author: Daniel Ellis 2022 Contact: daniel.ellis.research (a-t) gmail (dot) com Article: https://medium.com/p/e54de570d0bd ''' import mpmath as mp def get_tile(lat_deg,lon_deg,zoom): ''' Get the corresponding tile to a given longitude and latitude ''' lat_rad = mp.radians(lat_deg) #lat_deg * mp.pi / 180 n = 2 ** zoom xtile = n * ((lon_deg + 180) / 360) ytile = n * (1 - (mp.log(mp.tan(lat_rad) + mp.sec(lat_rad)) / mp.pi)) / 2 return 'tile: %d/%d/%d '%(zoom,xtile,ytile) def tile_translator(z,x,y,newzoom): '''Find the linking (left top) most tile from another zoom level''' n = 2 ** z x /= n y /= n n2 = 2 ** newzoom x *= n2 y *= n2 return '%d/%d/%d'%(newzoom,x,y) def get_children(z,x,y): ''' Retun the children of a tile ''' tile = list(map(int,(tile_translator(z,x,y,z+1).split('/')))) return [[tile[0],tile[1]+i,tile[2]+j] for i in [0,1] for j in [0,1]] def tile2lon(z,x,y) : return x / 2**z * 360 - 180; def tile2lat(z,x,y) : n = mp.pi - 2 * mp.pi * y / 2**z; return float((180 / mp.pi) * (mp.atan(0.5 * (mp.exp(n) - mp.exp(-n))))) def tile_bbox(z,x,y): ''' Return the bounding box of a tile ''' w = tile2lon(z,x,y) s = tile2lat(z,x,y) e = tile2lon(z,x+1,y) n = tile2lat(z,x,y+1) return [w,s,e,n]