diff --git a/bindings/python/mapnik_datasource.cpp b/bindings/python/mapnik_datasource.cpp index ab14d8638..5263a35b4 100644 --- a/bindings/python/mapnik_datasource.cpp +++ b/bindings/python/mapnik_datasource.cpp @@ -27,6 +27,7 @@ #include // mapnik #include +#include #include #include #include @@ -68,16 +69,44 @@ namespace } } +inline object pass_through(object const& o) { return o; } + +inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr) +{ + mapnik::feature_ptr f = itr->next(); + if (!f) + { + PyErr_SetString(PyExc_StopIteration, "No more features."); + boost::python::throw_error_already_set(); + } + return f; +} + void export_datasource() { using namespace boost::python; using mapnik::datasource; + using mapnik::Featureset; + using mapnik::Feature; + + class_, + boost::noncopyable>("Feature",no_init) + .def("id",&Feature::id) + .def("__str__",&Feature::to_string) + ; + + class_, + boost::noncopyable>("Datasource",no_init) + .def("next",next) + .def("__iter__",pass_through) + ; class_, boost::noncopyable>("Datasource",no_init) .def("envelope",&datasource::envelope) .def("descriptor",&datasource::get_descriptor) //todo .def("features",&datasource::features) + .def("features_at_point",&datasource::features_at_point) .def("params",&datasource::params,return_value_policy(), "The configuration parameters of the data source. " "These vary depending on the type of data source.")