I must draw a boundary of a natural reserve area in mapnik so that it looks like this:

boundary image

It is a partially opaque green polygon with a wide line border (also partially opaque) on the inside of the said polygon.

Now, the problem is - how do I tell mapnik (in style XML) to draw the line only on the inside(!) of the polygon.

Mapnik wants to draw the line axially centered at the polygon boundary, so that half of it always "hangs" outside of the polygon like this, and it is no Ok:

enter image description here

The code for the result you see is this:

  <Style name="nature_reserve">
        <PolygonSymbolizer fill="#4eaa2f" fill-opacity=".3" gamma=".2" />
        <LineSymbolizer stroke="#4eaa2f" stroke-opacity=".5" stroke-width="20" />

  <Layer name="nature_reserve" status="on" srs="+proj=longlat +datum=WGS84 +no_defs">
      <Parameter name="type">shape</Parameter>
      <Parameter name="file">data/osm/nature_reserve</Parameter>

I am a newbie to Mapnik, so that is about all I can think of. Any better suggestions?

Never mind the jagged lines, that is irrelevant now. All I care about is getting the outline inside the polygon.

Can it be offset somehow?

I did not find any options for this in documentation.

They are doing it in OpenStreetMap, so there must be the way:

enter image description here

  • What have you tried? What version of mapnik are you using? Please provide a code example of what you have so far.
    – Squanchy
    Commented Jun 29, 2018 at 14:27
  • Thanks for the answer! I added an update to the original post with extra info and code.
    – tasOvted
    Commented Jun 29, 2018 at 14:46

1 Answer 1


Yes, you can apply an offset.

Indeed, the openstreetmap-carto style does this in CartoCSS:

line-offset: -0.9;

The final XML for Mapnik is:

<LineSymbolizer offset="-0.9" stroke="#82643a" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.6" />

A negative offset means the line is shifted to the left (with regard to the direction of the line geometry), a positive offset means it is shifted to the right.

Apparently, when importing OSM ways to the “line” table, they keep their original direction. But when importing OSM ways (or multipolygon relations) to the “polygon” table, they do not keep their original direction; instead following OGC always at the left is the interior and at the right the exterior of the polygon. (This also applies to inner rings of multipolygons.) Therefore, this solution will only work when you import your geometries as (OGC) polygons, and not when you import them as lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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