fix access to mapnik::query::property_names in python - closes #1762
This commit is contained in:
parent
098f9de2aa
commit
7f0c745366
2 changed files with 27 additions and 0 deletions
|
@ -22,11 +22,15 @@
|
|||
|
||||
// boost
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/query.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
using mapnik::query;
|
||||
using mapnik::box2d;
|
||||
|
||||
|
@ -46,11 +50,30 @@ struct resolution_to_tuple
|
|||
}
|
||||
};
|
||||
|
||||
struct names_to_list
|
||||
{
|
||||
static PyObject* convert(std::set<std::string> const& names)
|
||||
{
|
||||
boost::python::list l;
|
||||
BOOST_FOREACH( std::string const& name, names )
|
||||
{
|
||||
l.append(name);
|
||||
}
|
||||
return python::incref(l.ptr());
|
||||
}
|
||||
|
||||
static PyTypeObject const* get_pytype()
|
||||
{
|
||||
return &PyList_Type;
|
||||
}
|
||||
};
|
||||
|
||||
void export_query()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
to_python_converter<query::resolution_type, resolution_to_tuple> ();
|
||||
to_python_converter<std::set<std::string>, names_to_list> ();
|
||||
|
||||
class_<query>("Query", "a spatial query data object",
|
||||
init<box2d<double>,query::resolution_type const&,double>() )
|
||||
|
|
|
@ -17,6 +17,10 @@ def test_query_init():
|
|||
r = query.resolution
|
||||
assert_almost_equal(r[0], 1.0, places=7)
|
||||
assert_almost_equal(r[1], 1.0, places=7)
|
||||
# https://github.com/mapnik/mapnik/issues/1762
|
||||
eq_(query.property_names,[])
|
||||
query.add_property_name('migurski')
|
||||
eq_(query.property_names,['migurski'])
|
||||
|
||||
# Converting *from* tuples *to* resolutions is not yet supported
|
||||
@raises(TypeError)
|
||||
|
|
Loading…
Reference in a new issue