3

I'm interested in creating a single SLD that could be used for a layer group in Geoserver that contains layers in point, line and polygon shapes.

According to docs it says:

"GeoServer supports the use of a StyledLayerDescriptor document containing a single < NamedLayer > element, which contains a single < UserStyle > element to specify the styling."

and then:

"A Style Layer Descriptor is a StyledLayerDescriptor document containing any number of < NamedLayer > and elements, each of which may contain any number of < UserStyle > or < NamedStyle > elements."

This seems to imply that I could use a single SLD for all my layers. I have created a SLD with multiple < NamedLayer >. However, only the first is being interpreted by Geoserver:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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>SAMPLE_EP_1</Name>
    <UserStyle>
      <Title>SAMPLE_EP_1</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>SAMPLE_EP_1</Title>
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>circle</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#5D8A82</CssParameter>
                </Fill>
             <Stroke>
               <CssParameter name="stroke">#000000</CssParameter>
               <CssParameter name="stroke-width">1</CssParameter>
             </Stroke>
              </Mark>
              <Size>6</Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>


  <NamedLayer>
    <Name>SAMPLE_EP_2</Name>
    <UserStyle>
      <Title>SAMPLE_EP_2</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>SAMPLE_EP_2</Title>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#5D8A82</CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>



  <NamedLayer>
    <Name>SAMPLE_EP_3</Name>
    <UserStyle>
      <Title>SAMPLE_EP_3</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>SAMPLE_EP_3</Title>
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">#FFFFFF</CssParameter>
              <CssParameter name="fill-opacity">1.0</CssParameter>
            </Fill>
            <Stroke>
              <CssParameter name="stroke">#FF69B4</CssParameter>
              <CssParameter name="stroke-width">1.0</CssParameter>
            </Stroke>
          </PolygonSymbolizer>

        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
  
  
    <NamedLayer>
    <Name>SAMPLE_EP_4</Name>
    <UserStyle>
      <Title>SAMPLE_EP_4</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>SAMPLE_EP_4</Title>
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">#BFFFCD
              </CssParameter>
            </Fill>
            <Stroke>
              <CssParameter name="stroke">#BFFFCD</CssParameter>
              <CssParameter name="stroke-width">1.0</CssParameter>
            </Stroke>
          </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
  
</StyledLayerDescriptor>

Any advice gratefully received!

1 Answer 1

4

That is possible, look into the GeoServer documentation for "style groups", for example, in these pages:

3
  • Thanks Andrea! Good to know it is possible. Thanks for the links. Any idea why the above SLD is causing Geoserver to only return the first <NamedLayer> section? It does validate ok but perhaps there is something missing.
    – Neil
    Jan 28, 2021 at 22:06
  • How are you using the style? The only way to make a multi-layer style to work, to my knowledge, is it configure it as a style group. Configured as the style of a particular layer, it will only use the first named layer content. Jan 29, 2021 at 15:39
  • Ah ok. I hadn't come across style groups before. I will have a go with that. Thanks!
    – Neil
    Feb 1, 2021 at 0:10

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.