GSIP 161

Torben Barsballe edited this page Aug 23, 2017 · 43 revisions

GSIP 161 - Style Based Layer Groups

Overview

This proposal makes this multi-layer SLD functionality accessible to a wider range of users through a modification to the GeoServer layer and layer group data model. This proposal allows a LayerGroup to contain both Layers, LayerGroups and StyleGroups (where a style group is defined by the associated SLD file).

See example at the end of this page for an example of a multi-layer SLD as currently supported by GeoServer.

Proposed By

Torben Barsballe, David Vick

Assigned to Release

This proposal is for GeoServer 2.12-beta.

State

  • Under Discussion
  • In Progress
  • Completed
  • Rejected
  • Deferred

Motivation

SLD provides the ability to reference multiple layers from a single GeoServer using NamedLayers. This is currently supported by GetMap in GeoServer (using an external style URL in your GetMap request).

This proposal makes this multi-layer SLD functionality accessible to a wider range of users through a modification to the GeoServer layer and layer group data model.

Proposal

Add a new method of defining layers in layer groups, referred to as a "style group". For this case, the "layer" entry would be null, and the style would be relied upon to define the layers included:

  1. Add support for style groups to the Layer Groups page in the Web UI: Add an "Add Style Group..." button after the existing "Add Layer..." and "Add Layer Group..." buttons.

    • Rather than bringing up a dialog, this button will just add a style group to the layers list.

    • The text "Style Group" (italicized, to differentiate it from a proper layer name) will show up under the Layer column. A null or default style will be equivalent to no style, and will show the text "Choose Style..." in the Style column.

    • Also add an (i) informational popup describing what a Style Group is and how it works.

    image

  2. Add support for this new functionality to the GeoServer style editor

    Add a "Style Group" option to the select preview layer dialog, which uses the WMS external SLD parameter to preview a style defining multiple named layers. This is technically entirely independent of the work necessary to add "Style Group" support, but will allow previewing styles as if they were being used as a StyleGroup or an external style.

  3. Add support for Style Groups to the layergroups REST API endpoint, e.g.

    PUT

       <layerGroup>
         <name>nyc</name>
         <layers>
           <layer></layer>
           <layer>parks</layer>
         </layers>
         <styles>
           <style>roads_style</style>
           <style>polygon</style>
         </styles>
       </layerGroup>
    

(The empty layer should be interpreted as null, and treated as a style group).

  1. Make the necessary changes to GeoServer WMS to support this new collection of layers.

    • Add logic to GetMapKvpRequestReader.java and GetMapXmlReader.java to handle Layer Groups being defined by a Style parameter.
         // ok, parse the styles parameter in isolation
         if (styleNameList.size() > 0) {
             List<Style> parseStyles = parseStyles(styleNameList);
             getMap.setStyles(parseStyles);
         }
    • After getting the list of styles add a method to process the styles, adding MapLayerInfo and Style to the WMS request for each NamedLayer.
    • If a style group refers to an invalid layer, it should throw a ServiceException, to match with the current treatment of layer groups.
  2. Add new validation for handling style groups / styles with named layers. For both these cases, it does not matter if the style is used as a style group, only that it has named layers.

    • Add a validation step for when layers are renamed or deleted.
      • In the UI, this will present itself as a dialog allowing the user to either rewrite the style, updating the name of the layer (Keeping a copy of the old style in the data directory for reference) or leaving the style as-is, to be updated by hand layer.
      • In the Rest API, this will present itself as a failure if such a rename or deletion would invalidate such a style. A new parameter ("styleUpdateStrategy") will be added allowing users to define a resolution strategy ("rewrite" style or "ignore"). The failure message will provide basic usage information for this parameter.
    • Add a new validation step for saving styles with named layers, which verifies that the named layers exist.

Using Style Groups

  1. Create (or upload) a new SLD file containing multiple NamedLayers and associated styles (See "Use of Multi-Layered SLD Files in GeoServer" below for an example of such an SLD). For the purposes of this example, this will be named "multilayer_style"

  2. Add a new layer group (named "lg_stylegroup"), and create a Style Group within it.

    1. To do this using the UI, got to the Layer Groups page, and click add layer group, and fill in the standard details. To add the style group, click New Style Group. Set the style for this entry to "multilayer_style" Associate your style with this Style Group, and save the layer group.

      image

    2. Using the REST API, POST the following to the /layergroups endpoint:

      <layerGroup>
        <name>lg_stylegroup</name>
        <layers>
          <layer></layer>
        </layers>
        <styles>
          <style>multilayer_style</style>
        </styles>
      </layerGroup>
      
    3. Optionally, you may add regular layers and layergroups to the "lg_stylegroup" layergroup alongside the style group.

  3. You will now be able to refer to "lg_stylegroup" in the LAYERS list of a WMS request. This will render a layer using the layers and styles defined in the "multilayer_style". Unlike using the SLD parameter, you can use additional layers alongside this one. For instance, you might define a basemap using a style group, and render addition layers on top of it.

    Like other layer groups, you can also view this one using the layer preview.

Backwards Compatibility

This change is additive-only, so there should be no backwards compatibility concerns.

Feedback

Voting

Project Steering Committee:

  • Alessio Fabiani:
  • Andrea Aime: +1
  • Ben Caradoc-Davies: +1
  • Brad Hards: +1
  • Christian Mueller:
  • Ian Turton: +1
  • Jody Garnett: +1
  • Jukka Rahkonen: +1
  • Kevin Smith: +1
  • Simone Giannecchini: +0

Links

Use of Multi-Layered SLD Files in GeoServer

(This represents existing functionality, which this GSIP is based on)

The following StyleLayerDescriptor document defines styling for an entire map, we do not generally use SLD in this fashion in the GeoServer codebase - but the functionality is supported by the WMS GetMap operations.

http://localhost:8080/geoserver/topp/wms?
  service=WMS&
  version=1.1.0&
  request=GetMap&
  SLD=http://localhost:8080/geoserver/styles/multilayer_style.sld&
  bbox=145.19754,-43.423512,148.27298000000002,-40.852802&
  width=768&
  height=641&
  srs=EPSG:4326&
  format=application/openlayers

Resulting in the following output:

image

Here is the reference multilayer_style.sld used for the above image:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" 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"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  <NamedLayer>
    <Name>topp:tasmania_water_bodies</Name>
    <UserStyle>
      <Title>Blue lake</Title>
      <Abstract>A blue fill, solid black outline style</Abstract>
      <FeatureTypeStyle>
        <Rule>
          <Name>name</Name>
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">
                <ogc:Literal>#f0f0C0</ogc:Literal>
              </CssParameter>
              <CssParameter name="fill-opacity">
                <ogc:Literal>1.0</ogc:Literal>
              </CssParameter>
            </Fill>
            <Stroke>
              <CssParameter name="stroke">
                <ogc:Literal>#000000</ogc:Literal>
              </CssParameter>
              <CssParameter name="stroke-linecap">
                <ogc:Literal>butt</ogc:Literal>
              </CssParameter>
              <CssParameter name="stroke-linejoin">
                <ogc:Literal>miter</ogc:Literal>
              </CssParameter>
              <CssParameter name="stroke-opacity">
                <ogc:Literal>1</ogc:Literal>
              </CssParameter>
              <CssParameter name="stroke-width">
                <ogc:Literal>1</ogc:Literal>
              </CssParameter>
              <CssParameter name="stroke-dashoffset">
                <ogc:Literal>0</ogc:Literal>
              </CssParameter>
            </Stroke>
          </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
  <NamedLayer>
    <Name>topp:tasmania_roads</Name>
    <UserStyle>

      <Title>Default Styler for simple road segments</Title>
      <Abstract>Light red line, 2px wide</Abstract>
      <FeatureTypeStyle>
        <Rule>
          <Title>Roads</Title>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">
                <ogc:Literal>#AA3333</ogc:Literal>
              </CssParameter>
              <CssParameter name="stroke-width">
                <ogc:Literal>2</ogc:Literal>
              </CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.