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:
parent
623a750ba4
commit
68bbcac872
1 changed files with 29 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <sstream>
|
||||
// mapnik
|
||||
#include <mapnik/envelope.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/datasource_cache.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()
|
||||
{
|
||||
using namespace boost::python;
|
||||
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>,
|
||||
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<copy_const_reference>(),
|
||||
"The configuration parameters of the data source. "
|
||||
"These vary depending on the type of data source.")
|
||||
|
|
Loading…
Reference in a new issue