More

Render all roads with an equal width in Mapnik

Render all roads with an equal width in Mapnik


Is there any easy way to render all roads and paths with an equal width in Mapnik? In the rendition below, all lines have the same line width, but since many of the bigger roads have many lanes or parallel roads that are (nearly) overlapping, they seem fatter.

My source for Mapnik is a PostGIS database with OSM data.

Any ideas?


Take a look at Skeletron, which is a Python tool to merge adjacent lines.

(Incidentally, I came here via your request in #osm IRC, but it would be polite for you to wait there a little more than 30 seconds to see if someone has an answer to your question!)


You can define different line widths in mapnik with a filter e.g.

 ([type]='motorway')   ([type]='primary') 

To create more complex mapnik files I usually use Tilemill because I find CartoCSS easier readable and well documented. For more information consult the guide for styling lines and the CartoCSS reference.

An example for styling road lines could be:

#roads { [type='motorway']{ line-width:.5; line-color:#168; } [type='primary']{ line-width:1; line-color:#168; } [type='secondary']{ line-width:1; line-color:#168; } [type='residential']{ line-width:1; line-color:#168; } }

After creating your map in Tilemill you can export the style as Mapnik XML which you can use then in your application.