I am currently generating tiles based on OSM data using Mapnik and Python and am quite happy using the XML styling but I am at a loss as to how to vary the styling on an element by element basis.

I would like to render OSM map tiles where certain elements are styled according to their attributes, for example, a roads colour is based on its length, or an area is coloured based on its size.

Is this possible?


If you use a Postgis database with osm2pgsql data scheme, you have a column way_area for polygons. Unit is square degrees or google meters, which is only at the aequator eqivalent to real metres:


For the length, I guess you have to calculate it on your own. But keep in mind that a road may have been broken up to reflect route relations diverting or joining.

  • Thanks, my main issue is with how to change the styling of the rendered item based on way_area or another variable. Currently I can only define the style that applies to all ways or all areas etc. – StuGrey Jan 16 '13 at 12:23
  • The Style "area-text" has a good example: <Filter>[way_area] &gt;= 80000 and [way_area] &lt; 150000</Filter> – AndreJ Jan 16 '13 at 12:59
  • Excellent, so if for instance I wanted to vary colour by size in small increments I would have to create a <filter> for each increment? I guess this is the way to do it if there is no way to directly base a colour on variable. The downside is that the style file could get very large. – StuGrey Jan 16 '13 at 13:09
  • You are right. The size of the style file is no problem: Every rule that does not fit simply gets skipped. – AndreJ Jan 16 '13 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.