artemp/mapnik — Issue #800: datasource plugins could provide statistics
Author: artemp
Created: 2011-10-11 16:37:16+00:00
State: open
Labels: Core_Library

Mapnik's design separates the concerns of data with style, allowing styles to be arbitrarily attached to layers. Thus styles and their logic intentionally have no way to get at data values, individually (like a first value) or in aggregate (like min/max). Styles, through Rules can only filter data based on expressions.

However, for thematic mapping, particularly dynamically changing choropleths, applications using mapnik need an easy way to introspect data, and get statistics *before* rendering. If this were possible then aggregate statistics could be calculated once, cached, and used then to change stylesheets on the fly.

This could be done by adding new functions on the datasource class: http://trac.mapnik.org/browser/trunk/include/mapnik/datasource.hpp#L104. The current datasource class design is largely based on rendering needs, but functions could be added that accept an attribute name and statistics type request (like max or min) and return the requested value in a boost::optional object (as perhaps some queries will not be possible/efficient for some datasources).