project logo

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. Type python on the command line to enter a python interpreter and 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')

Note

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

In addition 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”

To run the demo just follow these steps:

  1. Click Desktop ‣ Spatial Tools ‣ Start Mapnik & TileStache
  • The server should start in a terminal window (which stays open and outputs basic debugging information).
  1. Check to make sure the server is working by requesting a tile from the server at http://localhost:8012/example/0/0/0.png
  2. Then visit the Leaflet demo application page:

What Next?

  • Mapnik Tutorials

    Follow the tutorials to learn more about Mapnik.

  • Explore files on the DVD

    See also the included files on this DVD.