diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 5346f2c9b..70b361e75 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -83,24 +83,13 @@ void export_label_collision_detector(); #include #include #include "python_grid_utils.hpp" +#include "mapnik_value_converter.hpp" #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) #include static Pycairo_CAPI_t *Pycairo_CAPI; #endif - -namespace boost { namespace python { - - struct mapnik_value_to_python - { - static PyObject* convert(mapnik::value const& v) - { - return boost::apply_visitor(value_converter(),v.base()); - } - }; - }} - void render(const mapnik::Map& map, mapnik::image_32& image, double scale_factor = 1.0, @@ -651,5 +640,6 @@ BOOST_PYTHON_MODULE(_mapnik) register_ptr_to_python(); register_ptr_to_python(); + to_python_converter(); to_python_converter(); } diff --git a/bindings/python/mapnik_value_converter.hpp b/bindings/python/mapnik_value_converter.hpp index 292f84d14..bbac939b6 100644 --- a/bindings/python/mapnik_value_converter.hpp +++ b/bindings/python/mapnik_value_converter.hpp @@ -27,6 +27,7 @@ #include namespace boost { namespace python { + struct value_converter : public boost::static_visitor { PyObject * operator() (int val) const @@ -48,6 +49,13 @@ namespace boost { namespace python { return ::PyBool_FromLong(val); } + PyObject * operator() (std::string const& s) const + { + PyObject *obj = Py_None; + obj = ::PyUnicode_DecodeUTF8(s.c_str(),implicit_cast(s.length()),0); + return obj; + } + PyObject * operator() (UnicodeString const& s) const { std::string buffer; @@ -63,6 +71,25 @@ namespace boost { namespace python { } }; + + struct mapnik_value_to_python + { + static PyObject* convert(mapnik::value const& v) + { + return boost::apply_visitor(value_converter(),v.base()); + } + + }; + + struct mapnik_param_to_python + { + static PyObject* convert(mapnik::value_holder const& v) + { + return boost::apply_visitor(value_converter(),v); + } + }; + + } }