Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for encoding data as a raw image bitmap to UTF grids #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mapnik_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
using namespace boost::python;

// help compiler see template definitions
static dict (*encode)( mapnik::grid const&, std::string const& , bool, unsigned int) = mapnik::grid_encode;
static object (*encode)( mapnik::grid const&, std::string const& , bool, unsigned int) = mapnik::grid_encode;

bool painted(mapnik::grid const& grid)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ void export_grid()
.def("clear",&mapnik::grid::clear)
.def("encode",encode,
( boost::python::arg("encoding")="utf", boost::python::arg("features")=true,boost::python::arg("resolution")=4 ),
"Encode the grid as as optimized json\n"
"Encode the grid as optimized json or bitmap\n"
)
.add_property("key",
make_function(&mapnik::grid::get_key,return_value_policy<copy_const_reference>()),
Expand Down
4 changes: 2 additions & 2 deletions src/mapnik_grid_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
using namespace boost::python;

// help compiler see template definitions
static dict (*encode)( mapnik::grid_view const&, std::string const& , bool, unsigned int) = mapnik::grid_encode;
static object (*encode)( mapnik::grid_view const&, std::string const& , bool, unsigned int) = mapnik::grid_encode;

void export_grid_view()
{
Expand All @@ -57,7 +57,7 @@ void export_grid_view()
.def("height",&mapnik::grid_view::height)
.def("encode",encode,
( boost::python::arg("encoding")="utf",boost::python::arg("add_features")=true,boost::python::arg("resolution")=4 ),
"Encode the grid as as optimized json\n"
"Encode the grid as optimized json or bitmap\n"
)
;
}
Expand Down
27 changes: 20 additions & 7 deletions src/python_grid_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,23 +329,36 @@ void grid_encode_utf(T const& grid_type,
}

template <typename T>
boost::python::dict grid_encode( T const& grid, std::string const& format, bool add_features, unsigned int resolution)
boost::python::object grid_encode( T const& grid, std::string const& format, bool add_features, unsigned int resolution)
{
if (format == "utf") {
boost::python::dict json;
grid_encode_utf<T>(grid,json,add_features,resolution);
return json;
}
else
{
} else if (format == "raw") {
if (add_features) {
std::stringstream s;
s << "'raw' format does not support feature metadata";
throw mapnik::value_error(s.str());
}

if (resolution != 1) {
std::stringstream s;
s << "'raw' currently only supports resolution = 1";
throw mapnik::value_error(s.str());
}

const char * grid_data = reinterpret_cast<const char*>(grid.data().bytes());
return boost::python::str(grid_data, grid.data().size());
} else {
std::stringstream s;
s << "'utf' is currently the only supported encoding format.";
s << "'utf' and 'raw' are currently the only supported encoding formats.";
throw mapnik::value_error(s.str());
}
}

template boost::python::dict grid_encode( mapnik::grid const& grid, std::string const& format, bool add_features, unsigned int resolution);
template boost::python::dict grid_encode( mapnik::grid_view const& grid, std::string const& format, bool add_features, unsigned int resolution);
template boost::python::object grid_encode( mapnik::grid const& grid, std::string const& format, bool add_features, unsigned int resolution);
template boost::python::object grid_encode( mapnik::grid_view const& grid, std::string const& format, bool add_features, unsigned int resolution);

void render_layer_for_grid(mapnik::Map const& map,
mapnik::grid & grid,
Expand Down
2 changes: 1 addition & 1 deletion src/python_grid_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void grid_encode_utf(T const& grid_type,
unsigned int resolution);

template <typename T>
boost::python::dict grid_encode( T const& grid, std::string const& format, bool add_features, unsigned int resolution);
boost::python::object grid_encode( T const& grid, std::string const& format, bool add_features, unsigned int resolution);

void render_layer_for_grid(const mapnik::Map& map,
mapnik::grid& grid,
Expand Down