Style Lines in Geoserver

Style Lines in Geoserver

In this blog, we'll explore various ways to create styles for Line data. We'll be using SLD Format to write the styles. I would highly recommend to keep SLD Reference and LineString Style cookbook handy.

LineSymbolizer allows users to write Line Specific styles.

Line Data Representation

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A red line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Name>rule1</Name>
? ? ? ? ? <Title>Blue Line</Title>
? ? ? ? ? <Abstract>A solid blue line with a 1 pixel width</Abstract>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0000FF</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>

        

Line with border

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A red line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Name>rule1</Name>
? ? ? ? ? <Title>Blue Line</Title>
? ? ? ? ? <Abstract>A solid blue line with a 1 pixel width</Abstract>
? ? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#f00</CssParameter>
? ? ? ? ? ? ? ?<CssParameter name="stroke-width">5</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0000FF</CssParameter>
? ? ? ? ? ? ? ? <CssParameter name="stroke-width">3</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>

        

Line with graphic symbols

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A red line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Name>rule1</Name>
? ? ? ? ? <Title>Blue Line</Title>
? ? ? ? ? <Abstract>A solid blue line with a 1 pixel width</Abstract>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0000FF</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <GraphicStroke>
? ? ? ? ? ? ? ? <Graphic>
? ? ? ? ? ? ? ? ? <Mark>
? ? ? ? ? ? ? ? ? ? <WellKnownName>shape://vertline</WellKnownName>
? ? ? ? ? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? ? ? ? ? <CssParameter name="stroke">#333333</CssParameter>
? ? ? ? ? ? ? ? ? ? ? <CssParameter name="stroke-width">1</CssParameter>
? ? ? ? ? ? ? ? ? ? </Stroke>
? ? ? ? ? ? ? ? ? </Mark>
? ? ? ? ? ? ? ? ? <Size>5</Size>
? ? ? ? ? ? ? ? </Graphic>
? ? ? ? ? ? ? </GraphicStroke>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>

        

Line with Dash Array

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A red line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Name>rule1</Name>
? ? ? ? ? <Title>Blue Line</Title>
? ? ? ? ? <Abstract>A solid blue line with a 1 pixel width</Abstract>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0000FF</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-dashArray">5 2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>


        

?Line with Label

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A red line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Name>rule1</Name>
? ? ? ? ? <Title>Blue Line</Title>
? ? ? ? ? <Abstract>A solid blue line with a 1 pixel width</Abstract>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0000FF</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? ? <TextSymbolizer>
? ? ? ? ? <Label>
? ? ? ? ? ? <ogc:PropertyName>length_km</ogc:PropertyName>
? ? ? ? ? </Label>
? ? ? ? ? <Fill>
? ? ? ? ? ?<CssParameter name="fill">#000000</CssParameter>
? ? ? ? ?</Fill>
? ? ? ? </TextSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>

        

Line with Label following lines

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A red line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Name>rule1</Name>
? ? ? ? ? <Title>Blue Line</Title>
? ? ? ? ? <Abstract>A solid blue line with a 1 pixel width</Abstract>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0000FF</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? ? <TextSymbolizer>
? ? ? ? ? ? <Label>
? ? ? ? ? ? ? <ogc:PropertyName>length_km</ogc:PropertyName>
? ? ? ? ? ? </Label>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#000000</CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? ? <VendorOption name="followLine">true</VendorOption>
? ? ? ? ? </TextSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>

        

Line with Attributes based styling

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A gold line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0f0</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? ? <Rule>
? ? ? ? ? <ogc:Filter>
? ? ? ? ? ? <ogc:PropertyIsEqualTo>
? ? ? ? ? ? ? <ogc:PropertyName>continent</ogc:PropertyName>
? ? ? ? ? ? ? <ogc:Literal>Asia</ogc:Literal>
? ? ? ? ? ? </ogc:PropertyIsEqualTo>
? ? ? ? ? </ogc:Filter>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#FF0000</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>        

Line with Zoom (Scale) based styling

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A gold line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <MaxScaleDenominator>9000000</MaxScaleDenominator>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0f0</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? ? <Rule>
? ? ? ? ? <MinScaleDenominator>9000000</MinScaleDenominator>
? ? ? ? ? <MaxScaleDenominator>30000000</MaxScaleDenominator>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#FF0000</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">5</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? ? <Rule>
? ? ? ? ? <MinScaleDenominator>30000000</MinScaleDenominator>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#00f</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>        

Line with Intersection based on Location

No alt text provided for this image
<?xml version="1.0" encoding="ISO-8859-1"?>


<StyledLayerDescriptor version="1.0.0"
? ? ? ? ? ? ? ? ? ? ? ?xsi:schemaLocation="https://www.opengis.net/sld https://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:gml="https://www.opengis.net/gml"
? ? ? ? ? ? ? ? ? ? ? ?xmlns="https://www.opengis.net/sld" xmlns:ogc="https://www.opengis.net/ogc"
? ? ? ? ? ? ? ? ? ? ? ?xmlns:xlink="https://www.w3.org/1999/xlink" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">


? <NamedLayer>
? ? <Name>road</Name>
? ? <UserStyle>
? ? ? <Title>A gold line style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#0f0</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? ? <Rule>
? ? ? ? ? <ogc:Filter>
? ? ? ? ? ? <ogc:Intersects>
? ? ? ? ? ? ? <ogc:PropertyName>the_geom</ogc:PropertyName>
? ? ? ? ? ? ? <gml:Polygon>
? ? ? ? ? ? ? ? <gml:outerBoundaryIs>
? ? ? ? ? ? ? ? ? <gml:LinearRing>
? ? ? ? ? ? ? ? ? ? <gml:coordinates? decimal="." cs="," ts=" ">
? ? ? ? ? ? ? ? ? ? ? 73.125,19.932041306115536 73.125,17.644022027872726 76.4208984375,14.519780046326085 79.2333984375,20.3034175184893 79.2333984375,21.657428197370653 76.1572265625,21.779905342529645 74.3994140625,21.53484700204879 73.125,20.632784250388028 73.125,19.932041306115536? ? ? ? ? ? ?</gml:coordinates>
? ? ? ? ? ? ? ? ? </gml:LinearRing>
? ? ? ? ? ? ? ? </gml:outerBoundaryIs>
? ? ? ? ? ? ? </gml:Polygon>
? ? ? ? ? ? </ogc:Intersects>
? ? ? ? ? </ogc:Filter>
? ? ? ? ? <LineSymbolizer>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#FF0000</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">5</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </LineSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>?
        
No alt text provided for this image

Checkout My Other Articles dedicated to styling of Geoserver

No alt text provided for this image
Who am I ? ?????

Hi, I'm Krishna Lodha, I'm an open source GIS Developer, Contributor and Content creator. I have my agency Rotten Grapes Pvt. Ltd.? where we develop Web GIS Applications using Open source stack.?

Apart from development, I upload Videos about such technologies on YouTube. I upload new blogposts every now and then on this LinkedIn Newsletter. Make sure you Subscribe before you leave ?.

Comment Down What other conditions of style you have created in Geoserver !

S Lenin Kumar Reddy

Computer vision and Image Processing, Remote Sensing images

2 年

Nice work

回复
CHESTER SWANSON SR.

Next Trend Realty LLC./wwwHar.com/Chester-Swanson/agent_cbswan

2 年

Thanks for Sharing.

Duplex YOUNKAP NINA

Air Traffic Control Officer @ ASECNA | Geospatial Data Scientist, Product Manager @ Omdena | Python Developer | Leveraging AI & Open Source Solutions to Drive Impactful Projects

2 年

Awesome

回复

要查看或添加评论,请登录

Krishna Lodha的更多文章

  • Get Sentinel Data within seconds in?Python

    Get Sentinel Data within seconds in?Python

    With the development of STAC specification, accessing Satellite datasets have become easy and standard approach. This…

    1 条评论
  • The Ultimate Guide of Downloading OSM Data using ChatGPT

    The Ultimate Guide of Downloading OSM Data using ChatGPT

    Open Street Map is a collaborative mapping project that aims to create a free and editable map of the world. Unlike…

    7 条评论
  • Simple way of authentication for Geoserver

    Simple way of authentication for Geoserver

    Geoserver is an amazing tool which allows users to share spatial data of vector and raster type using OGC services like…

    1 条评论
  • Extending Openlayers capabilites

    Extending Openlayers capabilites

    If you have used openlayers in the past, you know it's capabilities very well. Openlayers allows users to put…

    10 条评论
  • Editing Feature directly via Geoserver

    Editing Feature directly via Geoserver

    GeoServer, an open-source geospatial server, provides powerful capabilities for serving and managing geospatial data…

    5 条评论
  • Custom popups in Geoserver

    Custom popups in Geoserver

    When we upload any layer to Geoserver, we can check the data on click by going in to Layer preview and display layer as…

    1 条评论
  • Install Geoserver on Mac OS

    Install Geoserver on Mac OS

    I use mac for most of my development purpose, and it’s already lil scary trying to install executables and libraries…

    3 条评论
  • Install Geoserver on Windows

    Install Geoserver on Windows

    I was recently trying to install Geoserver on a windows machine, until now I was using version 2.15, which had a…

    6 条评论
  • Install Geoserver on Ubuntu Server

    Install Geoserver on Ubuntu Server

    Geoserver is a JAVA based application developed to ease the styling and sharing of geospatial data using Opensource…

    7 条评论
  • Create Openlayers map in React Part 1

    Create Openlayers map in React Part 1

    Believe it or not! There is no active package available which harnesses the power of Openlayers with the Components of…

    4 条评论

社区洞察

其他会员也浏览了