Style Polygons in Geoserver

Style Polygons in Geoserver

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

PolygonSymbolizer allows users to write Polygon Specific styles.

Polygon 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>coun</Name>
? ? <UserStyle>
? ? ? <Title>A dark orange polygon style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <Title>dark orange polygon</Title>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#ff9900
? ? ? ? ? ? ? </CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#000000</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">0.5</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>        

Polygon Data with Graphic Symbol Fill

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>coun</Name>
? ? <UserStyle>
? ? ? <Title>A dark orange polygon style</Title>
? ? ? <FeatureTypeStyle>
? ? ? ? <Rule>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <GraphicFill>
? ? ? ? ? ? ? ? <Graphic>
? ? ? ? ? ? ? ? ? <Mark>
? ? ? ? ? ? ? ? ? ? <WellKnownName>shape://times</WellKnownName>
? ? ? ? ? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? ? ? ? ? <CssParameter name="stroke">#990099</CssParameter>
? ? ? ? ? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? ? ? ? ? </Stroke>
? ? ? ? ? ? ? ? ? </Mark>
? ? ? ? ? ? ? ? ? <Size>16</Size>
? ? ? ? ? ? ? ? </Graphic>
? ? ? ? ? ? ? </GraphicFill>
? ? ? ? ? ? </Fill>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#f00</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>        

Polygon Data with Attribute Conditions

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>
? ? ? ? ? <Title>Everything Else </Title>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#f00</CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </Rule>
? ? ? ? <Rule>
? ? ? ? ? <Title>Population > 90000000 </Title>
? ? ? ? ? <ogc:Filter>
? ? ? ? ? ? <ogc:PropertyIsGreaterThan>
? ? ? ? ? ? ? <ogc:PropertyName>POP_EST</ogc:PropertyName>
? ? ? ? ? ? ? <ogc:Literal>90000000</ogc:Literal>
? ? ? ? ? ? </ogc:PropertyIsGreaterThan>
? ? ? ? ? </ogc:Filter>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#0f0</CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </Rule>
? ? ? </FeatureTypeStyle>
? ? </UserStyle>
? </NamedLayer>
</StyledLayerDescriptor>
        

Polygon Data with Zoom (Scale) Conditions

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>
? ? ? ? ? <Title>Scale &lt; 9M</Title>
? ? ? ? ? <MaxScaleDenominator>9000000</MaxScaleDenominator>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#f00</CssParameter>
? ? ? ? ? ? ? <CssParameter name="fill-opacity">0.5</CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#000</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">5</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </Rule>


? ? ? ? <Rule>
? ? ? ? ? <Title>Scale between 9M and 30M</Title>
? ? ? ? ? <MinScaleDenominator>9000000</MinScaleDenominator>
? ? ? ? ? <MaxScaleDenominator>30000000</MaxScaleDenominator>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#0f0</CssParameter>
? ? ? ? ? ? ? <CssParameter name="fill-opacity">0.5</CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#000</CssParameter>
? ? ? ? ? ? ? <CssParameter name="stroke-width">2</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </Rule>
? ? ? ? <Rule>
? ? ? ? ? <Title>Scale &gt; 30M</Title>
? ? ? ? ? <MinScaleDenominator>30000000</MinScaleDenominator>
? ? ? ? ? <PolygonSymbolizer>
? ? ? ? ? ? <Fill>
? ? ? ? ? ? ? <CssParameter name="fill">#00f</CssParameter>
? ? ? ? ? ? </Fill>
? ? ? ? ? ? <Stroke>
? ? ? ? ? ? ? <CssParameter name="stroke">#000</CssParameter>
? ? ? ? ? ? </Stroke>
? ? ? ? ? </PolygonSymbolizer>
? ? ? ? </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??.

Vinay Gangare

Associate Technology Specialist at Tech Mahindra

2 年

This can be achieved if we are working with wms layer, so that sld can be created using qgis and other sources as well. But most challenging is that to add style on front end if we use wfs from geoserver mostly for polygon.

回复
CHESTER SWANSON SR.

Realtor Associate @ Next Trend Realty LLC | HAR REALTOR, IRS Tax Preparer

2 年

I'll keep this in mind.

Shadab Parvez Abidi

Manager - Technical Services specializing in Geospatial Technology, Digital Reality, Digital Twins and Emergency Response Systems

2 年

Would request/advise you to use correct India boundaries that includes the PoK and shows Laddakh and JnK to avoid displeasure with public and government agencies. The rest is informative like it always is with your blogs.

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

Krishna Lodha的更多文章

  • How to Generate Contour on the fly on GeoServer

    How to Generate Contour on the fly on GeoServer

    Digital Elevation Models (DEM) are crucial for terrain analysis, and contour lines are one of the best ways to…

    1 条评论
  • 5 Python Libraries for Earth Observation

    5 Python Libraries for Earth Observation

    Earth observation has become a cornerstone of the GIS industry, driven by the exponential growth in satellite missions…

    2 条评论
  • Digital Terrain Models in GIS: A Practitioner’s Guide to DSM, DTM, and DEM

    Digital Terrain Models in GIS: A Practitioner’s Guide to DSM, DTM, and DEM

    Picture yourself flying over a city in a helicopter. Looking down, you see buildings piercing the sky, trees dotting…

    3 条评论
  • 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 条评论

社区洞察

其他会员也浏览了