Bind statistics in Python

This commit is contained in:
Tom MacWright 2012-01-26 18:32:16 -05:00
parent 4c46385bf6
commit f3249c8fda

View file

@ -93,6 +93,24 @@ boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
return description; return description;
} }
boost::python::dict statistics(boost::shared_ptr<mapnik::datasource> const& ds)
{
boost::python::dict description;
std::map<std::string, mapnik::parameters> stats = ds->get_statistics();
std::map<std::string, mapnik::parameters>::iterator it;
for (it = stats.begin(); it != stats.end(); it++) {
boost::python::dict field;
mapnik::parameters::const_iterator k = it->second.begin();
for (; k != it->second.end(); ++k) {
field[k->first] = boost::get<double>(k->second);
}
description[it->first] = field;
}
return description;
}
boost::python::list fields(boost::shared_ptr<mapnik::datasource> const& ds) boost::python::list fields(boost::shared_ptr<mapnik::datasource> const& ds)
{ {
boost::python::list flds; boost::python::list flds;
@ -165,6 +183,7 @@ void export_datasource()
.def("type",&datasource::type) .def("type",&datasource::type)
.def("geometry_type",&datasource::get_geometry_type) .def("geometry_type",&datasource::get_geometry_type)
.def("describe",&describe) .def("describe",&describe)
.def("statistics",&statistics)
.def("envelope",&datasource::envelope) .def("envelope",&datasource::envelope)
.def("features",&datasource::features) .def("features",&datasource::features)
.def("bind",&datasource::bind) .def("bind",&datasource::bind)