User Tools

Site Tools


gis:getting_tiles_from_a_tile_server

Getting Tiles From a Tile Server

An interesting feature of tile servers is that the URLs used can easily be matched to paths so that it is possible to store those tiles in a pre-rendered form. Most sites prohibit excessive downloading of tiles so please only see the following script as a proof of concept. It can however be useful to potulate a caching proxy (in that case I'd suggest that you only fetch tiles up to zoom level 16. Beyond that level the number of features to be rendered per tile tends to be small and so rendering the tiles in real time will be fast enough for almost any purpose.

baseUrl=https://tileserver.example.com
suffix=.png
#curlOptions='--insecure'
 
if [ -z $map ]; then
  map=osm
fi
 
if [ $# -eq 1 ]; then
  basePath=$1
else
  basePath=.
fi
 
getTile () {
  if [ $# -eq 5 ]; then
    z=$1
    x0=$2
    x1=$3
    y0=$4
    y1=$5
    for x in $(seq $x0 $x1); do
      mkdir -p $basePath/$map/$z/$x
      for y in $(seq $y0 $y1); do
        filePath=$map/$z/$x/$y$suffix
        curl $curlOptions -o $basePath/$filePath $baseUrl/$filePath
      done
    done
  fi
}
 
getTile  0      0      0     0     0
getTile  1      1      1     0     0
getTile  2      2      2     1     1
getTile  3      4      4     2     2
getTile  4      8      8     5     5
getTile  5     16     16    10    10
getTile  6     33     33    21    21
getTile  7     66     66    42    43
getTile  8    132    133    85    86
getTile  9    265    266   171   172
getTile 10    531    532   343   344
getTile 11   1063   1065   687   688
getTile 12   2127   2130  1375  1377
getTile 13   4255   4260  2750  2755
getTile 14   8511   8520  5501  5511
getTile 15  17023  17040 11002 11022
getTile 16  34046  34080 22005 22045
getTile 17  68092  68161 44010 44091
getTile 18 136185 136322 88020 88183

The values are the limits for a map of Bonn, the same that are used in Installing a tile server on a Raspberry Pi 4: Pre-Rendering

gis/getting_tiles_from_a_tile_server.txt · Last modified: 2020/05/27 20:11 by admin