3

Does anyone know how to offset a stroke in Geoserver? For example I will color the left side of the street (line feature) red and the other side (same line feature) blue. I believe I will be using 2 LineSymbolizer for this but I don't know how to offset them. Otherwise, they will just be rendered on top of each other.

Any thoughts?

2
DISCLAIMER: My company financed the development of this plugin

There is a wonderful (!) plugin to achive this goal, it is Fluxomajic!

We developed it to render traffic information using Geoserver.

There is not so much documentation, you can go in to the code to get more information. An utilization example:

<Geometry>
<ogc:Function name="fluxo">            
    <ogc:PropertyName>shap</ogc:PropertyName>  <!-- SHAPE -->
    <ogc:Literal>7</ogc:Literal>               <!-- OFFSET -->
    <ogc:Literal>4000</ogc:Literal>         <!-- WIDTH -->
    <ogc:Literal>1</ogc:Literal>              <!-- driveMode (left/right) -->
    <ogc:Literal>4</ogc:Literal>             <!-- Numero quadranti default=16 -->
    <ogc:Literal>3</ogc:Literal>              <!-- ENDCAP style default=1(ROUND), 2(FLAT), 3(SQUARE) -->
    <ogc:Literal>1</ogc:Literal>              <!-- JOIN style default=1(ROUND), 2(MITRE), 3(BEVEL) -->
    <ogc:Function name="env">
       <ogc:Literal>wms_crs</ogc:Literal>
    </ogc:Function>
    <ogc:Function name="env">
       <ogc:Literal>wms_width</ogc:Literal>
    </ogc:Function>
    <ogc:Function name="env">
       <ogc:Literal>wms_height</ogc:Literal>
    </ogc:Function>
    <ogc:Function name="env">
       <ogc:Literal>wms_bbox</ogc:Literal>
    </ogc:Function>
 </ogc:Function>

Put the Geometry in a element, in an SLD.

  • Excellent, well done. Would you consider including the Jar file in Git for those of us who don't have Maven could use it or would the versioning required make that two difficult to maintain? – Mark Cupitt Nov 22 '13 at 0:28
  • Yes! That will really help a lot! Would there be any licensing issue by the way? – Angelo Arboleda Nov 22 '13 at 4:50
  • fluxomajic should be licenced with LGPL or GPL. For sure we are going to include the jar and a small SLD example on GitHub asap! – Tommaso Nov 22 '13 at 8:47
2

You can do line offsets using geometry "offset" function:

 <LineSymbolizer>
    <Geometry>
        <ogc:Function name="offset">
            <ogc:PropertyName>geom</ogc:PropertyName>
            <ogc:Literal>0.00004</ogc:Literal>
            <ogc:Literal>-0.00004</ogc:Literal>
        </ogc:Function>
    </Geometry>
    <Stroke>
        <CssParameter name="stroke">#000000</CssParameter>
        <CssParameter name="stroke-width">0.75</CssParameter>
    </Stroke>
 </LineSymbolizer>

Include two rules for LineSymbolizer, one with offset function and one w/o.

enter image description here

1

In Geoserver, a line is a line. You can draw different thicknesses of lines over the top of each other to create different road apperances.

There are only two options I can see:

  • Draw a wide line, say 10Px, then draw a 1Px line over the top of it to give the appearance of a Split Road, unfortunately this will not allow you to color one side differently from the other.

  • The only other option is to render two lines, x distance apart and style them seperately.

  • 1
    Actually, the only way to do that is using a 1px width png for styling the stroke, with half red and half blue. The problem is that, to get good results on several different scale, you have to produce different png, one for each scale. – Tommaso Nov 21 '13 at 8:42
1

EDIT: Since writing this a couple of years ago, there is now a much better solution available - the <PerpendicularOffset>. See the documentation for lines and polygons

ORIGINAL ANSWER (or: why geometry is not a great solution)
I was looking for a very similar thing (but with polygons) and artwork21's answer here directed my research. You can also do the same thing using Geoserver's CSS Extension as per this alternative solution:

* {
  stroke: #800000, #008000;
  stroke-geometry: [the_geom],[offset(the_geom, -0.005, 0.005)];
  stroke-width: 8, 10;
  stroke-linejoin: round;
  stroke-linecap: round;
}

Obviously set your offsets to suit. Offsets are in the same coordinate system (for both SLD and CSS) as the geometry (in this case DD). My stroke width is only so large to get a decent screenshot. Check out the function reference documentation here. To achieve this for polygons, I used the 'buffer' function (which only requires a single offset +/- and works as you would expect for a standard GIS buffer operation).

[STATE_NAME = 'Texas'] {
  stroke: #800000, #008000;
  stroke-geometry: [the_geom],[buffer(the_geom, -0.1)];
  stroke-width: 5, 12;
  stroke-linejoin: round;
  stroke-linecap: round;
}

However, this approach (mine or artwork21's) is only consistently good for polygons (using buffer) because the x, y values for the offset function are relative to the map and not the line. in the first image, you see can see how the offset is not consistent to the lines on some road features. In the second image you can see how the the buffer function produces a perfect stroke offset all around the inside of the polygon.

enter image description here

enter image description here

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.