Tiles and tiling/Setting up WMS or TMS

From OpenStreetMap Wiki
(Redirected from Setting up TMS)
Jump to: navigation, search
Available languages — Setting up TMS
Afrikaans Alemannisch aragonés asturianu azərbaycanca Bahasa Indonesia Bahasa Melayu Bân-lâm-gú Basa Jawa Baso Minangkabau bosanski brezhoneg català čeština dansk Deutsch eesti English español Esperanto estremeñu euskara français Frysk Gaeilge Gàidhlig galego Hausa hrvatski Igbo interlingua Interlingue isiXhosa isiZulu íslenska italiano Kiswahili Kreyòl ayisyen kréyòl gwadloupéyen Kurdî latviešu Lëtzebuergesch lietuvių magyar Malagasy Malti Nederlands Nedersaksies norsk bokmål norsk nynorsk occitan Oromoo oʻzbekcha/ўзбекча Plattdüütsch polski português português do Brasil română shqip slovenčina slovenščina Soomaaliga suomi svenska Tiếng Việt Türkçe Vahcuengh vèneto Wolof Yorùbá Zazaki српски / srpski беларуская български қазақша македонски монгол русский тоҷикӣ українська Ελληνικά Հայերեն ქართული नेपाली मराठी हिन्दी অসমীয়া বাংলা ਪੰਜਾਬੀ ગુજરાતી ଓଡ଼ିଆ தமிழ் తెలుగు ಕನ್ನಡ മലയാളം සිංහල ไทย မြန်မာဘာသာ ລາວ ភាសាខ្មែរ ⵜⴰⵎⴰⵣⵉⵖⵜ አማርኛ 한국어 日本語 中文(简体)‎ 吴语 粵語 中文(繁體)‎ ייִדיש עברית اردو العربية پښتو سنڌي فارسی ދިވެހިބަސް


You can set up a full WMS (Web Map Service) server to supply backdrop images to JOSM or Merkaartor. It is flexible and "does the right thing", but is a wee bit harder to set up.

  • You can use MapProxy. See also Mappproxy setup on this wiki
  • Needs input GeoTIFF raster map (or format known to GDAL).
  • Needs MapServer software running.
  • Needs Apache or some other web server running.
  • Needs gdal2tiles.py from GDAL 1.6.0 or newer. (MapSlicer may help)


You can set up a TMS (Tile Mapping Service) server to supply backdrop images to Merkaartor. This is a lot easier than setting up a full WMS, both in prep time and server load, but results are only really good for visual use. (The Google Mercator-on-a-sphere projection is not appropriate for "real" cartographic purposes) Think quick & dirty.

OSM's Slippy Tiles diverge from the above TMS spec in that its tiles start counting 0,0 from the top left, not the bottom left as the spec specs. (presumably someone started out by copying Google's tiles, which start 0,0 from the top-left)
Apparently Merkaartor 0.16 will ship with a tickbox in the TMS server setup dialog which allows you to reverse the tile order.
Some explanation of the options and coding details can be found in the gdal2tiles.py source code.
  • Needs input GeoTIFF raster map (or format known to GDAL).
  • Needs Apache or some other web server running.
  • Needs gdal2tiles.py from GDAL 1.6.0 or newer. (MapSlicer may help)
  • Needs Merkaartor 0.16 or newer to get tile order to match the OSGeo TMS spec. (otherwise it is reversed and in the wrong hemisphere)

Setting up the TMS

Install GDAL 1.6.0 or newer, including the python-gdal package on Debian/Ubuntu. Make sure gdal2tiles.py is present.

Create or download your GeoTIFF or GDAL-compatible & georegistered map.

If you want to tile multiple images, you might merge them first. A nice space-saving way is to use the gdal_vrtmerge.py example script to make a GDAL virtual raster which can then be fed to the main gdal2tiles.py program.

gdal_vrtmerge.py -o mosaic.vrt -i *.tif

In this case we will generate smoothed ('--resampling=average') maps for zoom scales 11-15 which is about right for this 1:50,000 scale map. Map is reprojected from its native projection on-the-fly (by gdalwarp).

gdal2tiles.py --profile=mercator --zoom=11-15 --title="NZTopo50" --copyright="Crown" "$MAP"

See "gdal2tiles.py --help" for details.

  • When it has finished generating the tiles copy the new directory onto your local webserver. View live by going to your web browser and loading up openlayers.html in that directory.
  • If the reprojection rotates the image at all you might end up with empty tiles. Here is a little Bourne shell script to remove them. (n.b. also removes solid greyscale tiles!)
for OUTFILE in `find | grep '\.png$'` ; do
    # check if image is empty
    CNT=`gdalinfo -mm -noct -nomd "$OUTFILE" | grep 'Min/Max' | \
       cut -f2 -d= | head -n 3 | tr ',' '\n' | uniq | wc -l`
    if [ "$CNT" -eq 1 ] ; then
       echo "Skipping blank image ..."
       \rm "$OUTFILE"

  • In Merkaartor setup is in Tools → TMS Servers Editor...
For the example above:
Server address
Tile size
Minimum zoom
Maximum zoom
Origin is bottom-left
  • [Add]