diff --git a/bindings/python/mapnik_query.cpp b/bindings/python/mapnik_query.cpp index f0041b8c0..3c6138a23 100644 --- a/bindings/python/mapnik_query.cpp +++ b/bindings/python/mapnik_query.cpp @@ -22,11 +22,15 @@ // boost #include +#include // mapnik #include #include +#include +#include + using mapnik::query; using mapnik::box2d; @@ -46,11 +50,30 @@ struct resolution_to_tuple } }; +struct names_to_list +{ + static PyObject* convert(std::set 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 (); + to_python_converter, names_to_list> (); class_("Query", "a spatial query data object", init,query::resolution_type const&,double>() ) diff --git a/tests/python_tests/query_test.py b/tests/python_tests/query_test.py index ec636da09..966d5877b 100644 --- a/tests/python_tests/query_test.py +++ b/tests/python_tests/query_test.py @@ -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)