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

Posted Aug 13, 2012 Tweet / Follow me on Twitter

Tom MacWright

I'm . I work on tools for creativity at Mapbox. This is where I write about technology and everything else.