I've just got a slippy map set-up using Mapnik to render OpenStreetMap data.

I've loaded SRTM elevation data following the PostGIS steps here and can now see contour lines on the map.

I'm trying to customise the contour line styling. Excuse my poor graphics skills in the following image, I thought it may be easier to use to communicate what I am trying to achieve.

enter image description here

I'm trying to style the contour lines in a way that the uphill edge of all the lines have a different colour from the downhill edge (in the above image red to indicate downhill and pink to indicate uphill).

I'm not sure what's the best way or if it's even possible to do using Mapnik styling but I thought of the following possibible options:

  1. Render a line then create a duplicate by calculating the centre of the lines circle, and then reduce or increase the ratio by a pixel.
  2. Render one line and then style using a colour gradient at 90 degrees to the line

I think the first option could produce some varied results given that the contours are all different shapes and sizes. I suspect there could end up being too much of a gap between the two lines in some cases.

The second I think would create a more accurate contour as there will only be one line and hopefully reduce rendering time too. The main difficulty I see with this is how the Mapnik styling can differentiate between the uphill and downhill edge.

  • 1
    Is it not the line-offset property that you are looking for? It will work with line-offset if the contour lines are all drawn in the same logical direction (eg they should be all right-hand drawn or left-hand drawn) – juminet May 18 at 10:08
  • Thanks that's exactly what I was looking for! If you can add as the answer I will accept. – algorhythm May 23 at 10:32

You are looking for the line-offset property of a Mapnik line symbolizer. This property allows to offset the lines by some pixels (so not geographically).

For offsetting some lines by some geographic distance, you may use the PostGIS function ST_OffsetCurve (in a pre-processing step or on-the-fly with mapnik).

To be sure that all contour lines will be rendered with a offset in the same direction, you have to ensure that they are all drawn in the same "order" (usually following the right-hand curve). It is usually the case when preparing the contour lines with some tools, but this may be broken in case you pre-process the contour lines.

| improve this answer | |

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.