OpenStreetMap logo OpenStreetMap

Grouping Mapnik's labels

Posted by Zverik on 29 April 2014 in English.

If you tried rendering quality maps with Mapnik, you know its label placement is awful. Just a bit better than throwing labels on map at random. So for printing, postprocessing in a vector editor is mandatory.

If you tried editing Mapnik-generated SVG, you know it is completely unstructured. Which means, if you need to move a label, first you have to select all of its letters one by one, and then its casing, also letter by letter. And there will be a lot of frustration when you select roads underneath the label, or lose selection.

Yesterday I’ve made a small script that takes Mapnik SVG, finds labels and wraps them in groups. So when you open that SVG in Inkscape, you will move labels not by letter, but as a whole.

https://github.com/Zverik/mapnik-group-text

The only parameter, -d, controls the maximum width of a letter, including spacing between letters. The default works for me, but if your labels are tightly packed, or are printed in a very large font, you may need to use that parameter.

Discussion

Comment from Endres Pelka on 29 April 2014 at 12:37

It would be better if Mapnik did it on its own when generating SVG.

Comment from Zverik on 29 April 2014 at 13:33

Of course, hard to argue with that. Sadly I don’t see even tickets in github tracker on that: closest thing is layered svg (which tilemill still does not produce). I’ve opened issue 2229.

Log in to leave a comment