Mapnik supports a variety of rendering backends. See OutputFormats for comparisons of different output formats.
The AGG renderer (Antigrain Geometry) is the primary renderer in Mapnik.
The Cairo renderer is an auxiliary renderer in Mapnik.
Writing to SVG with Mapnik's Cairo renderer:
import mapnik import cairo mapfile = 'mapfile.xml' projection = '+proj=latlong +datum=WGS84' mapnik_map = mapnik.Map(1000, 500) mapnik.load_map(mapnik_map, mapfile) bbox = mapnik.Envelope(-180.0,-90.0,180.0,90.0) mapnik_map.zoom_to_box(bbox) # Write to SVG surface = cairo.SVGSurface('mapfile.svg', mapnik_map.width, mapnik_map.height) mapnik.render(mapnik_map, surface) surface.finish() # Or write to PDF surface = cairo.PDFSurface('mapfile.pdf', mapnik_map.width, mapnik_map.height) mapnik.render(mapnik_map, surface) surface.finish()
The SVG renderer is written by Carlos López Garcés, started as part of GSOC 2010 and the "better printing project". The idea is that while the Cairo backend offers both PDF and SVG support, we can do better by having a custom implementation to handle things such as layer grouping, re-used of svg/bitmap symbols, and texts on paths. Only the basics are implemented at this point and those needed custom features are still a ways off, but the renderer has much promise. Currently is is not built by default but can be enabled with the build flag
The svg_renderer uses some very cool features of boost karma to generate SVG really fast and should be a good example of ways to leverage boost karma more in the future, potentially for other types of innovative vector output.
The Grid renderer is designed to output highly optimized feature "hit grids", known as UTFGrids (based on the final encoding format). It does this by leveraging and extending modular parts of the antigrain geometry library to rasterize feature id's into a buffer, then outputs metadata about the relevant feature attributes for the given ids, all enclosed within a compact, highly compressible json file using utf8 encoded feature ids for space efficiency. The grid_renderer was first available in the Mapnik 2.0.0 release.
The UTFGrid spec provides details of the format:
See the implementations list for examples:
Last edited by Dane Springmeyer,