156a7590f4
This plugin allows you to write data sources in the Python programming language. This is useful if you want to rapidly prototype a plugin, perform some custom manipulation on data or if you want to bind mapnik to a datasource which is most conveniently accessed through Python. The plugin may be used from the existing mapnik Python bindings or it can embed the Python interpreter directly allowing it to be used from C++, XML or even JavaScript. Mapnik already has excellent Python bindings but they only directly support calling *into* mapnik *from* Python. This forces mapnik and its input plugins to be the lowest layer of the stack. The role of this plugin is to allow mapnik to call *into* Python itself. This allows mapnik to sit as rendering middleware between a custom Python frontend and a custom Python datasource. This increases the utility of mapnik as a component in a larger system. There already exists MemoryDatasource which can be used to dynamically create geometry in Python. It suffers from the problem that it does not allow generating only the geometry which is seen by a particular query. Similarly the entire geometry must exist in memory before rendering can progress. By using a custom iterator object or by using generator expressions this plugin allows geometry to be created on demand and to be destroyed after use. This can have a great impact on memory efficiency. Since geometry is generated on-demand as rendering progresses there can be arbitrarily complex 'cleverness' optimising the geometry generated for a particular query. Obvious examples of this would be generating only geometry within the query bounding box and generating geometry with an appropriate level of detail for the output resolution.
30 lines
685 B
C++
30 lines
685 B
C++
// boost
|
|
#include <boost/python.hpp>
|
|
|
|
#include "python_featureset.hpp"
|
|
#include "python_utils.hpp"
|
|
|
|
python_featureset::python_featureset(boost::python::object iterator)
|
|
{
|
|
ensure_gil lock;
|
|
begin_ = boost::python::stl_input_iterator<mapnik::feature_ptr>(iterator);
|
|
}
|
|
|
|
python_featureset::~python_featureset()
|
|
{
|
|
ensure_gil lock;
|
|
begin_ = end_;
|
|
}
|
|
|
|
mapnik::feature_ptr python_featureset::next()
|
|
{
|
|
// checking to see if we've reached the end does not require the GIL.
|
|
if(begin_ == end_)
|
|
return mapnik::feature_ptr();
|
|
|
|
// getting the next feature might call into the interpreter and so the GIL must be held.
|
|
ensure_gil lock;
|
|
|
|
return *(begin_++);
|
|
}
|
|
|