8

I have a line layer in geoserver as in the 1st image.

How can I draw an arrow on the line like in the 2nd image?

The line.rar includes a shapefile and a sld file.

Can edit a sample for me?

line.rar(download)

enter image description here enter image description here

0

1 Answer 1

16

The GeoServer documentations states how to extract start and end points with geometry transformations (just use the end- point rule). The code example provided uses square as marks, but you could always replace this with e.g. the shape symbol shape://oarrow.

EDIT: I forgot to mention how to rotate the triangle correctly (couldn't find it in the documentation, but took it from page 38 in this presentation)!

<Rotation>
<ogc:Function name="endAngle">
<ogc:PropertyName>the_geom</ogc:PropertyName>
</ogc:Function>
</Rotation>

EDIT2: Just wanted to make sure everything works as described, here is a code sample based on GeoServer's default blue line SLD style:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" 
        xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
        xmlns="http://www.opengis.net/sld" 
        xmlns:ogc="http://www.opengis.net/ogc" 
        xmlns:xlink="http://www.w3.org/1999/xlink" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <NamedLayer>
        <Name>Blue arrows</Name>
        <UserStyle>
            <Title>A blue line with end arrows</Title>
            <FeatureTypeStyle>
                <Rule>
                    <Name>Blue_Arrow_Line</Name>
                    <LineSymbolizer>
                        <Stroke>
                            <CssParameter name="stroke">#0000FF</CssParameter>
                            <CssParameter name="stroke-width">2</CssParameter>
                        </Stroke>
                    </LineSymbolizer>
                    <PointSymbolizer>
                        <Geometry>
                            <ogc:Function name="endPoint">
                                <ogc:PropertyName>the_geom</ogc:PropertyName>
                            </ogc:Function>
                        </Geometry>
                        <Graphic>
                            <Mark>
                                <WellKnownName>shape://oarrow</WellKnownName>
                                <Fill>
                                <CssParameter name="fill">#0000FF</CssParameter>
                                <CssParameter name="fill-opacity">0.5</CssParameter>
                                </Fill>
                                <Stroke>
                                    <CssParameter name="stroke">#0000FF</CssParameter>
                                    <CssParameter name="stroke-width">2</CssParameter>
                                </Stroke>
                            </Mark>
                            <Size>30</Size>
                            <Rotation>
                                <ogc:Function name="endAngle">
                                    <ogc:PropertyName>the_geom</ogc:PropertyName>
                                </ogc:Function>
                            </Rotation>
                        </Graphic>
                    </PointSymbolizer>
                </Rule>
            </FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>

This is how it should look like:

Blue Arrow Example image

4
  • SAnderka, thanks a lot. I use the edit2 way and it runs wonderful on geoserver.
    – user23048
    Commented Oct 10, 2014 at 3:11
  • There is a grey checkmark underneath this question's voting buttons. You need to click it (it'll turn green) to mark your question as answered in GIS SE's system. Thanks!
    – SAnderka
    Commented Oct 13, 2014 at 7:29
  • I've been trying to get this to work using CSS styles and cannot do it. Can anyone help with that? I though I was on to something with this but it does not work: [@scale > 1] { geometry: startPoint(geom); mark: symbol(triangle); mark-size:10px; }
    – ca0v
    Commented Apr 15, 2017 at 11:54
  • This may help if you're trying something like this in css: [@scale > 1] { mark-geometry: [startPoint(geom)]; mark: symbol(arrow); mark-size:10px; mark-rotation: [endAngle(geom)]; :mark { fill: white; stroke: black; } }
    – ca0v
    Commented Apr 15, 2017 at 12:06

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.