Friday 2 April 2010

Experimental PDF Branch

'experimental_pdf' is a branch of Mapnik's source code in which the author provided functionality for printing maps to pdf format. At the time when it was developed, Mapnik offered no support for doing so directly, so the author based the rendering process on a third-party library called 'wxPDFDocument', a C++ port of a PHP library for creating PDF documents (http://wxcode.sourceforge.net/components/wxpdfdoc/). PDF support was added when cairo_renderer was introduced, some time after experimental_pdf began development.

Features

experimental_pdf has some features not yet found in Mapnik. These features include:

  • A border around the map showing geographical coordinates (longitude and latitude). An example can be found in the GMT project's website [1].
  • A grid on top of the map, representing longitude and latitude lines, also called meridians and parallels, respectively.
  • A scale bar that shows the scale of the map graphically. The scale of a map is expressed as a ratio that indicates the relationship between units of measurement in the map and in the real world.
  • Overlay images.
  • A correspondence between map layers and PDF layers. Each layer of the map is rendered in a different PDF layer, thus allowing the user to hide elements of the map using a PDF viewer (much like it is possible in applications like AI and PS [2]).

In addition to these features, this renderer is capable of producing output to fit PDF document pages of various sizes, performing scale calculations to resize the elements of the map properly.

It has been suggested by members of the Mapnik community that some of these features should be included as part of the development of the project (Better Print Support).

The Code

From my point of view, the design and code of the experimental_pdf branch resembles the structure of the agg_renderer, Mapnik's primary renderer:

  • It provides a renderer class, called 'pdf_renderer', that inherits from 'feature_style_renderer'. Both agg_renderer and cairo_renderer are subclasses of feature_style_renderer, too.
  • It makes use of a graphics API for performing the actual rendering, wxPdfDocument.
  • It implements some symbolizers found in Mapnik's core: point_symbolizer, shield_symbolizer, line_pattern_symbolizer, and polygon_pattern_symbolizer. Other symbolizers, such as polygon_symbolizer, building_symbolizer, and line_symbolizer, are processed using the original implementation (it doesn't provide subclasses for these symbolyzers). The markers_symbolizer was left unimplemented, however.
  • It implements the methods for processing each symbolizer inside the pdf_renderer class.


Figure 1. Oversimplified design view of the experimental pdf branch.

I've been trying to compile the code and see the output generated. However, the scons build file is not updated. Visual Studio project files were provided, but I haven't installed Mapnik on Windows.

A more thorough discussion on this topic can be found in mapnik-devel's mailing list [3]. The last post is from April 6 2008, so it's been a while since this branch was last updated.

References

  1. http://gmt.soest.hawaii.edu/
  2. http://help.adobe.com/en_US/Acrobat/8.0/Professional/help.html?content=WS58a04a822e3e50102bd615109794195ff-7c5e.html
  3. http://www.mail-archive.com/mapnik-devel@lists.berlios.de/msg00095.html

* This post is intended to capture the ideas of the following e-mails:

  • http://www.mail-archive.com/mapnik-devel@lists.berlios.de/msg00646.html
  • http://www.mail-archive.com/mapnik-devel@lists.berlios.de/msg00655.html
  • http://www.mail-archive.com/mapnik-devel@lists.berlios.de/msg00656.html

No comments:

Post a Comment