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.
This commit is contained in:
Artem Pavlenko 2006-12-01 10:08:13 +00:00
parent 623a750ba4
commit 68bbcac872

View file

@ -27,6 +27,7 @@
#include <sstream> #include <sstream>
// mapnik // mapnik
#include <mapnik/envelope.hpp> #include <mapnik/envelope.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <mapnik/feature_layer_desc.hpp> #include <mapnik/feature_layer_desc.hpp>
@ -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() void export_datasource()
{ {
using namespace boost::python; using namespace boost::python;
using mapnik::datasource; using mapnik::datasource;
using mapnik::Featureset;
using mapnik::Feature;
class_<Feature,boost::shared_ptr<Feature>,
boost::noncopyable>("Feature",no_init)
.def("id",&Feature::id)
.def("__str__",&Feature::to_string)
;
class_<Featureset,boost::shared_ptr<Featureset>,
boost::noncopyable>("Datasource",no_init)
.def("next",next)
.def("__iter__",pass_through)
;
class_<datasource,boost::shared_ptr<datasource>, class_<datasource,boost::shared_ptr<datasource>,
boost::noncopyable>("Datasource",no_init) boost::noncopyable>("Datasource",no_init)
.def("envelope",&datasource::envelope) .def("envelope",&datasource::envelope)
.def("descriptor",&datasource::get_descriptor) //todo .def("descriptor",&datasource::get_descriptor) //todo
.def("features",&datasource::features) .def("features",&datasource::features)
.def("features_at_point",&datasource::features_at_point)
.def("params",&datasource::params,return_value_policy<copy_const_reference>(), .def("params",&datasource::params,return_value_policy<copy_const_reference>(),
"The configuration parameters of the data source. " "The configuration parameters of the data source. "
"These vary depending on the type of data source.") "These vary depending on the type of data source.")