Mapnik Quickstart

Mapnik is an toolkit for developing mapping applications. Above all Mapnik is about making beautiful maps. It is easily extensible and suitable for both desktop and web development.

Mapnik & Python

Mapnik and its python bindings are installed and ready to be used for scripting on this machine.

Creating maps in python is easy with Mapnik. Open a terminal window and type python on the command line to enter a python interpreter. Then try this:

>>> import mapnik, os
>>> m = mapnik.Map(600,400)
>>> style = '/usr/local/share/mapnik/demo/population.xml'
>>> mapnik.load_map(m,style)
>>> m.zoom_all()
>>> mapnik.render_to_file(m,'map.png')
>>> os.system('xdg-open map.png')


The above code depends on having an XML stylesheet that Mapnik can read, defining the layers to read data from and the styles to apply to those layers. You can create one of these inside QGIS with the Quantumnik plugin: http://plugins.qgis.org/plugins/quantumnik/

Mapnik & Leaflet

A basic demo application is available which highlights using Mapnik to serve tiles into an OpenLayers web map in the OSM/Google tile scheme.

The demo uses a tileserver designed for Mapnik called “TileStache”. Visit the TileStache website for more information: http://tilestache.org/

  1. Click Desktop ‣ Spatial Tools ‣ Start Mapnik & TileStache. The server starts in a terminal window (which stays open and outputs basic debugging information).
  2. Check that the server is working by requesting a tile from the server. Click this link http://localhost:8012/example/0/0/0.png and observe the output in the server terminal window.
  3. Visit the Leaflet demo application page http://localhost/leaflet-demo.html.

What next?