Example Code

The Mapnik source comes with some example code in the mapnik/demo directory.

Here are some other sets of Example Code to learn from.


C++ Code

California

  • Name: cali.cpp
  • Description: A sample program, adapted from demo/c++/rundemo.cpp which demonstrates how one might use the Mapnik C++ API to render the state of California from USGS Shapefile data.
  • Source: http://gist.github.com/5009
  • Tested On: Mac OS 10.5
  • Added by: lwu

Python Code

Hello World

World Population

Cairo Renderer

Code samples for writing to SVG and PDF

mapnik-utils

The mapnik-utils project includes some example code as well: http://code.google.com/p/mapnik-utils/

PostGIS

ExampleCodePythonPostGIS -- Python code that talks to PostGIS

ShieldSymbolizer

An e-mail on Mapnik ShieldSymbolizer. Also describes use of

$ python 
 >>>import mapnik 
 >>>dir(mapnik) 
 >>>help(mapnik) 

and

$ pydoc -p 8080 
and then open a browser and go to : 
http://localhost:8080/mapnik.html