2

I have designed an SLD for a line format shapefile in GeoServer, in which I am using an arrow symbol as shown in figure.

line format shapefile

The code is:

<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld"
    xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
    <sld:NamedLayer>
        <sld:Name>Blue arrows</sld:Name>
        <sld:UserStyle>
            <sld:Name>Blue arrows</sld:Name>
            <sld:FeatureTypeStyle>
                <sld:Name>name</sld:Name>
                <sld:Rule>
                    <sld:Title>A blue line with end arrows</sld:Title>
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">#73ed5d</sld:CssParameter>
                            <sld:CssParameter name="stroke-width">3.26</sld:CssParameter>
                            <sld:CssParameter name="stroke-linejoin">bevel</sld:CssParameter>
                            <sld:CssParameter name="stroke-linecap">square</sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:LineSymbolizer>
                        <!--<sld:VendorOption name="placement">centralPoint</sld:VendorOption>-->
                        <sld:Stroke>
                            <sld:GraphicStroke>
                                <sld:Graphic>
                                    <sld:Mark>
                                        <sld:WellKnownName>shape://oarrow</sld:WellKnownName>
                                        <sld:Fill>
                                            <sld:CssParameter name="fill">#0000FF</sld:CssParameter>
                                            <sld:CssParameter name="fill-opacity"
                                                >0.5</sld:CssParameter>
                                        </sld:Fill>
                                        <sld:Stroke>
                                            <sld:CssParameter name="stroke"
                                                >#0000FF</sld:CssParameter>
                                            <sld:CssParameter name="stroke-width"
                                                >1</sld:CssParameter>
                                        </sld:Stroke>
                                    </sld:Mark>
                                    <Size>20</Size>
                                </sld:Graphic>
                            </sld:GraphicStroke>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                </sld:Rule>
            </sld:FeatureTypeStyle>
        </sld:UserStyle>
    </sld:NamedLayer>
</sld:StyledLayerDescriptor>

I have to specify distance between this arrows.

1
  • 1
    Are you trying to specify in geo-distance or pixels? – BradHards May 13 '16 at 11:34
1

The <Size> setting of 20 in your XML specifies an arrow length of 10 pixels followed by a gap of 10 pixels before the next arrow starts being drawn. If you add a dasharray to the XML inside the <sld:Stroke> tag as follows:

<sld:Stroke>
    <sld:CssParameter name="stroke">#0000FF</sld:CssParameter>
    <sld:CssParameter name="stroke-width">1</sld:CssParameter>
    <sld:CssParameter name="stroke-dasharray">11 0</sld:CssParameter>
</sld:Stroke>    

Then each arrow will be 10 pixels long with a 1 pixel gap between them.
If you then modify the XML inside the <sld:Stroke> tag as follows:

<sld:Stroke>
    <sld:CssParameter name="stroke">#0000FF</sld:CssParameter>
    <sld:CssParameter name="stroke-width">1</sld:CssParameter>
    <sld:CssParameter name="stroke-dasharray">11 29</sld:CssParameter>
</sld:Stroke>   

Then each arrow will be 10 pixels long with a 30 pixel gap between them. The two values in the dash array indicate, respectively, the number of pixels pen-down, then number of pixels pen-up.

If you want to make the gap between arrows proportional to your map scale then you could try this:

<sld:Stroke>
    <sld:CssParameter name="stroke">#0000FF</sld:CssParameter>
    <sld:CssParameter name="stroke-width">1</sld:CssParameter>
    <sld:CssParameter name="stroke-dasharray">11 
        <ogc:Div>                
            <ogc:Literal>377953</ogc:Literal>
            <ogc:Function name="env">
                <ogc:Literal>wms_scale_denominator</ogc:Literal>
            </ogc:Function>    
        </ogc:Div>
    </sld:CssParameter>   
</sld:Stroke>

Which aims for approx 100m gaps.

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.