Tom MacWright

tom@macwright.com

Images as Maps

The question comes up surprisingly often: how does one create fictional maps - like World of WarCraft maps - in a modern cartography system like TileMill?

I’ve made non-geographical maps before, but never anything with raster data or properly dodging the distortion of projections and their distortions.

This is a Python script: download it as a raw file, name it togeo.py. You’ll need GDAL for it to work - not necessarily the ‘python bindings’, but make sure that, in your terminal, gdal_translate and gdalinfo are present.

Run the script with a single filename as its argument:

python togeo.py pie.jpeg

(if you’ve got an image format other than JPEG, convert your image to JPEG first with a graphics application, graphicsmagick, or a free online conversion service)

This will generate pie.jpeg.tif or yourfile.jpeg.tif, geo-referenced. What I mean by ‘geo-referenced’ is that the tif file is now a GeoTIFF file - a TIFF file with special information about what projection it’s in and where its corners are in the world. This script transforms the image into the spherical mercator projection, and then does some extra legwork to make sure that its corners are referenced in a way that respects the image’s aspect ratio.

The way that it does that is pretty simple: the maximum bounds of a GeoTIFF in EPSG:900913 is -20037508.34, -20037508.34, 20037508.34, 20037508.34. togeo.py simply crops this either widthwise or lengthwise to fit a smaller area and preserve the image’s dimensions.

From there, you can use it in TileMill or your favorite GeoTIFF-supporting application (QGIS is another good one) easily!

See Also

  • GSV by Mike Migurski doesn’t make any geo-assumptions and includes a Python script for tiling.
  • Zoomify takes the product angle and is popular with photographers.
  • You can hack the Google Maps API to produce a similar effect, or use OpenLayers
  • If your images have something to do with the world, and you want to combine them with other maps, none of these techniques will work: you should check out image rectification. Map Warper and Map Knitter are great options for doing that.