mod_tile icon indicating copy to clipboard operation
mod_tile copied to clipboard

UTFGrid support for mod_tile

Open mikelmaron opened this issue 10 years ago • 7 comments

Trying to get mod_tile producing UTF8Grids. Wondering if anyone else has looked at this. Apparently the fix would be in mapnik itself. Some notes on this from @springmeyer below.

The reason renderd does not support tile end points for interactivity/grids is that Mapnik support is partially in C++ and partially in the bindings (python or JavaScript). It ended up this way because to leverage the json support in each of those languages and not implement the full json encoding for utf8grids in C++. But in doing so, renderd needs to implement that json encoding on its own, which has not happened yet and likely shouldn't since ideally Mapnik would just do this in C++ to save the duplicative work.

The grid_renderer builds up an image like array of feature ids. Then that needs to be turned into json. The code to do it is is already in c++ actually but writes to a c++ boost python object. Instead it would need to write to a string that could be parseable as json. The bindings code is mapnik/bindings/python/python_grid_utils.hpp. We don't actually need a json encoder and the intermediate objects it would likely require.

mikelmaron avatar Dec 07 '13 14:12 mikelmaron

Adding UTFGrid is somewhere on my todo list and I have had a brief look at it in the past.

If full UTFGrid support would be added to mapnik's C++ api, that would be great and should make support for it much easier in renderd. However, given that mapnik can already create the grid objects, albeit as boost binary object, it shouldn't be that difficult to add it to renderd anyway, as it is mostly about serialising the data out to a json string.

If I remember correctly, you still need to style the UTFGrid stuff to declare what to include, so one question would be how best to pass this information on to renderd?

@mikelmaron are you planning on working on this? I might be able to help if you are.

apmon avatar Dec 24 '13 00:12 apmon

@apmon yes I plan to work on this soon, and would really appreciate help.

The variables for a UTFGrid are the layer, fields, and templates for teaser and full. The templates are not actually served in the grids, but defined in application javascript typically, so renderd/mapnik only needs to be aware of the layer and fields. Options I can think of would be to extend mapnik XML config to define these, or to add the definitions to renderd.conf.

My preference right now is to build this support into renderd as you suggest, and the config into renderd.conf as well, so we can build this feature without dependency on a mapnik release. If mapnik later supported UTFGrid output directly, then renderd can update.

mikelmaron avatar Dec 26 '13 10:12 mikelmaron

@mikelmaron @apmon Any progress/further thoughts on this?

systemed avatar Aug 21 '14 17:08 systemed

I gave up and switched to TileStache for girds. Would still consider moving it all to one (or the other), but don't have time.  

  • Mikel Maron * +14152835207 @mikel s:mikelmaron

On Thursday, August 21, 2014 1:19 PM, Richard Fairhurst [email protected] wrote:

@mikelmaron @apmon Any progress/further thoughts on this? — Reply to this email directly or view it on GitHub.

mikelmaron avatar Aug 21 '14 17:08 mikelmaron

I could be interested in working on this (as otherwise I'm going to have to move a project to Tilestache) but my knowledge of the mod_tile/renderd codebase is non-existent. Any pointers would be appreciated.

systemed avatar Jan 05 '15 16:01 systemed

I am trying to write one. You can see the code at https://github.com/sri-soham/mapnik-utf8grid-tester . I am able to generate tiles for the given x, y, z but the utf grid is coming up empty.

As I see it, the problem is with writing features to grid with grid-renderer. Relevant code being

mapnik::grid_renderer<mapnik::grid> ren(m_map, my_grid, 1.0, 0, 0);
std::vector<mapnik::layer> const& layers = m_map.layers();
ren.apply(layers[0], attributes);

in this file https://github.com/sri-soham/mapnik-utf8grid-tester/blob/master/map_tile.cpp .

I am new to mapnik and c++. Any pointers in getting this right?

Thanks

sri-soham avatar Apr 01 '17 08:04 sri-soham

Grid generation is working now. Used the python_grid_utils scripts from the python-mapnik repo. Replaced the python data structures with c++ data structures and it works for now. If any of you can review the code, it will be very helpful.

Thanks.

sri-soham avatar Apr 08 '17 07:04 sri-soham