From 68bbcac872249a8fd290b7d938643e09a4b13fc6 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 1 Dec 2006 10:08:13 +0000 Subject: [PATCH] Reflect featureset and feature classes in Python. Featureset follows Python iterator protocol e.g: ds = Shapefile(file="/../..") for f in ds.features_at_point(Coord(-2,51)): print f TODO: 1.access to Feature properties 2.feature_at_point to accept screen coordinates 3.apply hit_test for geometries. --- bindings/python/mapnik_datasource.cpp | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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.")