Friday, August 06, 2010

Creating a large map from OpenStreetMap map tiles

We where planning at work to print large maps of the BSR on plywood and create a puzzle out of it, I think it was 1x1 meter. I made the following simple bash script to download and stitch the tiles using ImageMagick:

#!/bin/sh
#From
#http://c.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256/7/66/26.png
#To:
#http://b.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256/7/76/42.png
Z=7
URL=http://tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256/

download_tile() {
 FILE=tile_${x}_${y}.png
 if [ -r $FILE ]; then 
  echo .
 else
  curl --output tile_${x}_${y}.png ${URL}/${Z}/${1}/${2}.png
 fi
}

for ((x=66;x<77;x++)) do
  for ((y=26;y<43;y++)) do
   download_tile $x $y
   sleep 0.1
  done
  montage -geometry 256x256 -tile 1x17 tile_${x}* map_${x}.png
  sleep 1
done

Unfortunately printing and large sticker or directly on plywood was out of the budget so in the end it wasn't needed. The fallback was handpainting, not as accurate, but looks pretty good still.
Anyway, I post this tiny script in here in case someone else might need something like it as I didn't find anything suitable when I was searching for a quick and simple solution. The best would of course had been to create a custom map using mapnik and all that, but it would have take too much time (and I don't have any hardware to play with at work, only my laptop with a tiny disk)

No comments: