diff --git a/bindings/python/mapnik_geometry.cpp b/bindings/python/mapnik_geometry.cpp index df1b946b9..e084eed01 100644 --- a/bindings/python/mapnik_geometry.cpp +++ b/bindings/python/mapnik_geometry.cpp @@ -50,6 +50,7 @@ #include // from_wkt/to_wkt #include // from_geojson #include // to_geojson +#include // to_wkb //#include #include @@ -59,7 +60,6 @@ namespace { - std::shared_ptr from_wkb_impl(std::string const& wkb) { std::shared_ptr geom = std::make_shared(); @@ -99,43 +99,24 @@ inline std::string boost_version() return s.str(); } -//PyObject* to_wkb(mapnik::geometry_type const& geom, mapnik::util::wkbByteOrder byte_order) -//{ -// mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,byte_order); -// if (wkb) -// { -// return -//#if PY_VERSION_HEX >= 0x03000000 -// ::PyBytes_FromStringAndSize -//#else -// ::PyString_FromStringAndSize -//#endif -// ((const char*)wkb->buffer(),wkb->size()); -// } -// else -// { -// Py_RETURN_NONE; -// } -//} - -//PyObject* to_wkb2( mapnik::geometry_container const& p, mapnik::util::wkbByteOrder byte_order) -//{ -// mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(p,byte_order); -// if (wkb) -// { -// return -//#if PY_VERSION_HEX >= 0x03000000 -// ::PyBytes_FromStringAndSize -//#else -// ::PyString_FromStringAndSize -//#endif -// ((const char*)wkb->buffer(),wkb->size()); -// } -// else -// { -// Py_RETURN_NONE; -// } -//} +PyObject* to_wkb(mapnik::new_geometry::geometry const& geom, mapnik::wkbByteOrder byte_order) +{ + mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,byte_order); + if (wkb) + { + return +#if PY_VERSION_HEX >= 0x03000000 + ::PyBytes_FromStringAndSize +#else + ::PyString_FromStringAndSize +#endif + ((const char*)wkb->buffer(),wkb->size()); + } + else + { + Py_RETURN_NONE; + } +} std::string to_geojson_impl(mapnik::new_geometry::geometry const& geom) { @@ -243,7 +224,7 @@ void export_geometry() .def("is_simple", &geometry_is_simple_impl) .def("correct", &geometry_correct_impl) .def("centroid",&geometry_centroid_impl) - //.def("to_wkb",&to_wkb) + .def("to_wkb",&to_wkb) .def("to_wkt",&to_wkt_impl) .def("to_geojson",&to_geojson_impl) //.def("to_svg",&to_svg)