Tiles and tiling/Setting up WMS or TMS

From OpenStreetMap Wiki
Jump to navigation Jump to search

WMS

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)

TMS

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

See also: GDAL2Tiles

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).

MAP="CI04_GeoTif_1-00.tif"
gdal2tiles.py --profile=mercator --zoom=11-15 --title="NZTopo50" --copyright="Crown" "$MAP"
</source>

See "<code>gdal2tiles.py --help</code>" 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!)

<syntaxhighlight lang="bash">
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"
       continue
    fi
done
  • In Merkaartor setup is in Tools → TMS Servers Editor...
For the example above:
Name
NZTopo50
Server address
localhost
Path
maps/CI04_GeoTif_1-00/%1/%2/%3.png
Tile size
256
Minimum zoom
11
Maximum zoom
15
Origin is bottom-left
"x"
  • [Add]