22 *
33 * This file is part of Mapnik (c++ mapping toolkit)
44 *
5- * Copyright (C) 2015 Artem Pavlenko
5+ * Copyright (C) 2024 Artem Pavlenko
66 *
77 * This library is free software; you can redistribute it and/or
88 * modify it under the terms of the GNU Lesser General Public
2121 *****************************************************************************/
2222
2323#if defined(GRID_RENDERER)
24-
25- #include < mapnik/config.hpp>
26-
27-
28- #pragma GCC diagnostic push
29- #include < mapnik/warning_ignore.hpp>
30- #include < boost/python.hpp>
31- #include < boost/python/module.hpp>
32- #include < boost/python/def.hpp>
33- #pragma GCC diagnostic pop
34-
3524// mapnik
25+ #include < mapnik/config.hpp>
3626#include < mapnik/grid/grid.hpp>
3727#include " python_grid_utils.hpp"
3828
39- using namespace boost ::python;
29+ // pybind11
30+ #include < pybind11/pybind11.h>
31+
32+ namespace py = pybind11;
4033
4134// help compiler see template definitions
42- static dict (*encode)( mapnik::grid const &, std::string const & , bool , unsigned int ) = mapnik::grid_encode;
35+ static py:: dict (*encode)( mapnik::grid const &, std::string const & , bool , unsigned int ) = mapnik::grid_encode;
4336
4437bool painted (mapnik::grid const & grid)
4538{
@@ -53,32 +46,27 @@ mapnik::grid::value_type get_pixel(mapnik::grid const& grid, int x, int y)
5346 mapnik::grid::data_type const & data = grid.data ();
5447 return data (x,y);
5548 }
56- PyErr_SetString (PyExc_IndexError, " invalid x,y for grid dimensions" );
57- boost::python::throw_error_already_set ();
58- return 0 ;
49+ throw py::index_error (" invalid x,y for grid dimensions" );
5950}
6051
61- void export_grid ()
52+ void export_grid (py:: module const & m )
6253{
63- class_<mapnik::grid,std::shared_ptr<mapnik::grid> >(
64- " Grid" ,
65- " This class represents a feature hitgrid." ,
66- init<int ,int ,std::string>(
67- ( boost::python::arg (" width" ), boost::python::arg (" height" ),boost::python::arg (" key" )=" __id__" ),
68- " Create a mapnik.Grid object\n "
69- ))
54+ py::class_<mapnik::grid, std::shared_ptr<mapnik::grid>>
55+ (m, " Grid" , " This class represents a feature hitgrid." )
56+ .def (py::init<int ,int ,std::string>(),
57+ " Create a mapnik.Grid object\n " ,
58+ py::arg (" width" ), py::arg (" height" ), py::arg (" key" )=" __id__" )
7059 .def (" painted" ,&painted)
7160 .def (" width" ,&mapnik::grid::width)
7261 .def (" height" ,&mapnik::grid::height)
7362 .def (" view" ,&mapnik::grid::get_view)
7463 .def (" get_pixel" ,&get_pixel)
7564 .def (" clear" ,&mapnik::grid::clear)
76- .def (" encode" ,encode,
77- ( boost::python::arg (" encoding" )=" utf" , boost::python::arg (" features" )=true ,boost::python::arg (" resolution" )=4 ),
78- " Encode the grid as as optimized json\n "
79- )
80- .add_property (" key" ,
81- make_function (&mapnik::grid::get_key,return_value_policy<copy_const_reference>()),
65+ .def (" encode" , encode,
66+ " Encode the grid as as optimized json\n " ,
67+ py::arg (" encoding" ) = " utf" , py::arg (" features" ) = true , py::arg (" resolution" ) = 4 )
68+ .def_property (" key" ,
69+ &mapnik::grid::get_key,
8270 &mapnik::grid::set_key,
8371 " Get/Set key to be used as unique indentifier for features\n "
8472 " The value should either be __id__ to refer to the feature.id()\n "
0 commit comments