Using Styled Layer Descriptors with WMS services

Styled Layer Descriptors (SLDs) allow you to publish various symbolization schemes for your WMS service using an XML specification defined by the Open Geospatial Consortium, Inc. (OGC). Alternatively, clients of your service can use their own SLDs to apply the symbols they choose.

SLD files and SLD styles

An SLD file is an XML file that follows the OGC SLD syntax so that it can be understood in server-client communication.

SLD styles are physically saved in the SLD file. Logically, one such SLD style defines symbolization rules for specified sets of features within a specified WMS layer. One style can have multiple rules, and each rule can have one filter that describes which features should be rendered and multiple symbolizers that describe how those features should be rendered.

Here is a sample SLD XML document:

Sample SLD 1.0.0 XML document

The implementation of WMS SLD in ArcGIS Server is based on the OGC Styled Layer Descriptor (SLD) Implementation Specification. To get a general overview of SLD, see the Styled Layer Descriptor page on the OGC Web site.

Publishing multiple styles with SLDs

You can use the following workflow to publish multiple styles for WMS layers using SLD:

  1. Create a WMS service with system-generated capabilities files.
  2. Create a single SLD XML document that defines multiple styles for each layer in the WMS service.
  3. Bind the SLD XML with the WMS service.

To accomplish this, follow these steps in ArcCatalog or ArcGIS Server Manager:

  1. Start ArcCatalog or log in to ArcGIS Server Manager.
  2. Publish a WMS service, using the instructions in WMS services.
  3. Create an XML document in SLD syntax that defines additional styles for each WMS layer you want to publish. You can save this SLD XML document to the local disk or make it accessible as a URL.
  4. Stop the map service if it's still running.
  5. Open the map service properties dialog box. To do this in ArcCatalog, right-click an existing map service and click Service Properties. In ArcGIS Server Manager, click the Edit icon of an existing map service on the Services tab.
  6. Click the Capabilities tab.
  7. In the capabilities list, check WMS if it's not checked yet.
  8. Below the Properties section of the Capabilities tab, you will see the SLD URL or Path text box. Type the URL of your SLD XML or use the file browser to locate your SLD XML on your local disk.
  9. Restart the map service.
  10. To make sure the SLD XML is correctly bound with the WMS service, do one of the following:
    • Issue a WMS GetCapabilities request in the browser. In the XML response, there should be one <Style> element being advertised for each additional style you defined in the SLD for each WMS layer.
    • Examine the folder <map_service_output_directory>\<service_name_MapServer>\wms\. There should be one legend image file being generated for each additional style you defined in the SLD for each WMS layer.

To see working examples of SLDs, visit the WMS Styled Layer Descriptor samples.

Changing the style of a WMS map in ArcGIS Desktop

Once you bind an SLD XML file to an ArcGIS Server WMS service, applicable styles will be picked up for each layer and advertised through that WMS service's capabilities information. Certain WMS clients like ArcMap will then be aware of those styles and will allow you switch between those styles.

Each WMS service sublayer in ArcMap has a Layer Properties dialog box. On this dialog box, there is a Style tab where you can choose which SLD you want to use for the layer.

NoteNote:

Many other WMS clients, like Gaia and uDig, allow different styles for a WMS layer as long as those styles are listed in the WMS service's capabilities information.

Using external SLDs from the client side

With ArcGIS Server WMS services, users are not limited to the styles published on the server. Clients can reference an applicable SLD file in the WMS GetMap request so that the WMS service renders the map using their own styles.

Using an external SLD from the client side involves the following steps:

  1. Create a single SLD XML document that defines multiple styles for each layer in the WMS service, or you can use a public SLD XML if it's applicable to your WMS service.
  2. Make the SLD XML accessible through a URL that is accessible to the server (if you use a public SLD XML, make sure it's accessible as a URL).
  3. Change the values of the LAYERS and STYLES parameters in the original WMS HTTP GetMap request to indicate which style the WMS server should use to render each layer.
  4. Send the SLD XML to the WMS server and request the map by adding one more key-value parameter pair (SLD=<sld_xml_url>) to the end of a WMS HTTP GetMap request string.

How SLD_BODY works

An alternative to sending SLD styles to the server is to use the standard WMS GetMap request parameter SLD_BODY. Unlike the parameter SLD, the value of SLD_BODY contains the actual XML body of an SLD document. By using SLD_BODY, it is possible for a client to dynamically modify the WMS layer styles without the SLD document being exposed through a public URL.

NoteNote:

Currently few desktop WMS clients support SLD_BODY. Most of the practical use cases for SLD_BODY are in Web clients like OpenLayers and the ArcGIS API for JavaScript, with which application developers have the flexibility to modify the GetMap request to append SLD_BODY.

Using SLD_BODY from the client side involves the following steps:

  1. Create a single SLD XML document that defines multiple styles for each layer in the WMS service, or you can use a public one as long as you can access the SLD XML.
  2. Change the values of the LAYERS and STYLES parameters in the original WMS HTTP GetMap request to indicate which style the WMS server should use to render each layer.
  3. Send the SLD XML to the WMS server and request the map by adding one more key-value parameter pair (SLD_BODY=<sld_xml_body>) to the end of the WMS HTTP GetMap request string.

SLD_BODY examples

Sample request 1

http://myserver/arcgis/services/OGC/SanFrancisco/MapServer/WMSServer?LAYERS=highways&STYLES=style_sld_body&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&CRS=CRS%3A84&SLD_BODY=%3Csld%3AStyledLayerDescriptor%20xmlns%3Asld%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%22%20version%3D%221.0.0%22%20xsi%3AschemaLocation%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%20http%3A%2F%2Fschemas.opengis.net%2Fsld%2F1.0.0%2FStyledLayerDescriptor.xsd%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%20xmlns%3Agml%3D%22http%3A%2F%2Fwww.opengis.net%2Fgml%22%3E%3Csld%3ANamedLayer%3E%3Csld%3AName%3Ehighways%3C%2Fsld%3AName%3E%3Csld%3ANamedStyle%3E%3Csld%3AName%2F%3E%3C%2Fsld%3ANamedStyle%3E%3Csld%3AUserStyle%3E%3Csld%3AName%3Estyle_sld_body%3C%2Fsld%3AName%3E%3Csld%3ATitle%3Eroad_types%3C%2Fsld%3ATitle%3E%3Csld%3AFeatureTypeStyle%3E%3Csld%3ARule%3E%3Csld%3AName%3Ecalles%3C%2Fsld%3AName%3E%3Csld%3ATitle%3Ecalles%3C%2Fsld%3ATitle%3E%3Csld%3ALineSymbolizer%3E%3Csld%3AStroke%3E%3Csld%3ACssParameter%20name%3D%22stroke%22%3E%23FFFF00%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-width%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linejoin%22%3Eround%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linecap%22%3Eround%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AStroke%3E%3C%2Fsld%3ALineSymbolizer%3E%3C%2Fsld%3ARule%3E%3Csld%3ARule%3E%3Csld%3AName%3Eautopista%3C%2Fsld%3AName%3E%3Csld%3ATitle%3Eautopista%3C%2Fsld%3ATitle%3E%3Cogc%3AFilter%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3Cogc%3APropertyIsEqualTo%3E%3Cogc%3APropertyName%3EROAD_TYPE%3C%2Fogc%3APropertyName%3E%3Cogc%3ALiteral%3EMajor%20Roads%2FHighways%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3APropertyIsEqualTo%3E%3C%2Fogc%3AFilter%3E%3Csld%3ALineSymbolizer%3E%3Csld%3AStroke%3E%3Csld%3ACssParameter%20name%3D%22stroke%22%3E%230000FF%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-width%22%3E2%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linejoin%22%3Eround%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linecap%22%3Eround%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AStroke%3E%3C%2Fsld%3ALineSymbolizer%3E%3C%2Fsld%3ARule%3E%3Csld%3ARule%3E%3Csld%3AName%3Erampa%3C%2Fsld%3AName%3E%3Csld%3ATitle%3Erampa%3C%2Fsld%3ATitle%3E%3Cogc%3AFilter%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3Cogc%3APropertyIsEqualTo%3E%3Cogc%3APropertyName%3EHWYNAME%3C%2Fogc%3APropertyName%3E%3Cogc%3ALiteral%3ERAMP%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3APropertyIsEqualTo%3E%3C%2Fogc%3AFilter%3E%3Csld%3ALineSymbolizer%3E%3Csld%3AStroke%3E%3Csld%3ACssParameter%20name%3D%22stroke%22%3E%2300FF00%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-width%22%3E2%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linejoin%22%3Eround%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linecap%22%3Eround%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AStroke%3E%3C%2Fsld%3ALineSymbolizer%3E%3C%2Fsld%3ARule%3E%3C%2Fsld%3AFeatureTypeStyle%3E%3C%2Fsld%3AUserStyle%3E%3C%2Fsld%3ANamedLayer%3E%3C%2Fsld%3AStyledLayerDescriptor%3E&BBOX=-122.64942090625,37.6087920625,-122.25391309375,37.8724639375&WIDTH=1152&HEIGHT=768

Response to sample request 1

Response to Sample Request 1

Sample request 2

http://myserver/arcgis/services/OGC/SanFrancisco/MapServer/WMSServer? LAYERS=pizzastores&STYLES=style_sld_body&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&SLD_BODY=%3Csld%3AStyledLayerDescriptor%20xmlns%3Asld%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%22%20version%3D%221.0.0%22%20xsi%3AschemaLocation%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%20http%3A%2F%2Fschemas.opengis.net%2Fsld%2F1.0.0%2FStyledLayerDescriptor.xsd%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%20xmlns%3Agml%3D%22http%3A%2F%2Fwww.opengis.net%2Fgml%22%3E%3Csld%3ANamedLayer%3E%3Csld%3AName%3Epizzastores%3C%2Fsld%3AName%3E%3Csld%3ANamedStyle%3E%3Csld%3AName%2F%3E%3C%2Fsld%3ANamedStyle%3E%3Csld%3AUserStyle%3E%3Csld%3AName%3Estyle_sld_body%3C%2Fsld%3AName%3E%3Csld%3ATitle%3Epizza%3C%2Fsld%3ATitle%3E%3Csld%3AFeatureTypeStyle%3E%3Csld%3ARule%3E%3Csld%3AName%3Edefault%3C%2Fsld%3AName%3E%3Csld%3APointSymbolizer%3E%3Csld%3AGraphic%3E%3Csld%3AExternalGraphic%3E%3Csld%3AOnlineResource%20xlink%3Atype%3D%22simple%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20xlink%3Ahref%3D%22http%3A%2F%2Fzeon%2Fresources%2Fsld%2Fsanfrancisco%2Fimages%2Fpizza.gif%22%2F%3E%3Csld%3AFormat%3EGIF%3C%2Fsld%3AFormat%3E%3C%2Fsld%3AExternalGraphic%3E%3Csld%3AOpacity%3E1%3C%2Fsld%3AOpacity%3E%3Csld%3ASize%3E12%3C%2Fsld%3ASize%3E%3Csld%3ARotation%3E0%3C%2Fsld%3ARotation%3E%3C%2Fsld%3AGraphic%3E%3C%2Fsld%3APointSymbolizer%3E%3C%2Fsld%3ARule%3E%3C%2Fsld%3AFeatureTypeStyle%3E%3C%2Fsld%3AUserStyle%3E%3C%2Fsld%3ANamedLayer%3E%3C%2Fsld%3AStyledLayerDescriptor%3E&BBOX=-122.64942090625,37.6087920625,-122.25391309375,37.8724639375&WIDTH=1152&HEIGHT=768

Response to sample request 2

Response to Sample Request 2

Sample request 3

http://myserver/arcgis/services/OGC/SanFrancisco/MapServer/WMSServer? LAYERS=blockgroups&STYLES=style_sld_body&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&SLD_BODY=%3Csld%3AStyledLayerDescriptor%20xmlns%3Asld%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%22%20version%3D%221.0.0%22%20xsi%3AschemaLocation%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%20http%3A%2F%2Fschemas.opengis.net%2Fsld%2F1.0.0%2FStyledLayerDescriptor.xsd%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%20xmlns%3Agml%3D%22http%3A%2F%2Fwww.opengis.net%2Fgml%22%3E%3Csld%3ANamedLayer%3E%3Csld%3AName%3Eblockgroups%3C%2Fsld%3AName%3E%3Csld%3ANamedStyle%3E%3Csld%3AName%2F%3E%3C%2Fsld%3ANamedStyle%3E%3Csld%3AUserStyle%3E%3Csld%3AName%3Estyle_sld_body%3C%2Fsld%3AName%3E%3Csld%3AFeatureTypeStyle%3E%3Csld%3ARule%3E%3Csld%3AName%3E0%20-%20784%3C%2Fsld%3AName%3E%3Csld%3ATitle%3E0%20-%20784%3C%2Fsld%3ATitle%3E%3Cogc%3AFilter%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3Cogc%3APropertyIsBetween%3E%3Cogc%3APropertyName%3EPOP1990%3C%2Fogc%3APropertyName%3E%3Cogc%3ALowerBoundary%3E%3Cogc%3ALiteral%3E0%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3ALowerBoundary%3E%3Cogc%3AUpperBoundary%3E%3Cogc%3ALiteral%3E784%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3AUpperBoundary%3E%3C%2Fogc%3APropertyIsBetween%3E%3C%2Fogc%3AFilter%3E%3Csld%3APolygonSymbolizer%3E%3Csld%3AFill%3E%3Csld%3ACssParameter%20name%3D%22fill%22%3E%23FFFF80%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22fill-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AFill%3E%3Csld%3AStroke%3E%3Csld%3ACssParameter%20name%3D%22stroke%22%3E%23FF3300%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-width%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linejoin%22%3Eround%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linecap%22%3Eround%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AStroke%3E%3C%2Fsld%3APolygonSymbolizer%3E%3C%2Fsld%3ARule%3E%3Csld%3ARule%3E%3Csld%3AName%3E785%20-%201571%3C%2Fsld%3AName%3E%3Csld%3ATitle%3E785%20-%201571%3C%2Fsld%3ATitle%3E%3Cogc%3AFilter%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3Cogc%3APropertyIsBetween%3E%3Cogc%3APropertyName%3EPOP1990%3C%2Fogc%3APropertyName%3E%3Cogc%3ALowerBoundary%3E%3Cogc%3ALiteral%3E785%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3ALowerBoundary%3E%3Cogc%3AUpperBoundary%3E%3Cogc%3ALiteral%3E1571%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3AUpperBoundary%3E%3C%2Fogc%3APropertyIsBetween%3E%3C%2Fogc%3AFilter%3E%3Csld%3APolygonSymbolizer%3E%3Csld%3AFill%3E%3Csld%3ACssParameter%20name%3D%22fill%22%3E%23F7C348%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22fill-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AFill%3E%3Csld%3AStroke%3E%3Csld%3ACssParameter%20name%3D%22stroke%22%3E%230033FF%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-width%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linejoin%22%3Eround%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linecap%22%3Eround%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AStroke%3E%3C%2Fsld%3APolygonSymbolizer%3E%3C%2Fsld%3ARule%3E%3Csld%3ARule%3E%3Csld%3AName%3E1572%20-%204737%3C%2Fsld%3AName%3E%3Csld%3ATitle%3E1572%20-%204737%3C%2Fsld%3ATitle%3E%3Cogc%3AFilter%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3Cogc%3APropertyIsBetween%3E%3Cogc%3APropertyName%3EPOP1990%3C%2Fogc%3APropertyName%3E%3Cogc%3ALowerBoundary%3E%3Cogc%3ALiteral%3E1572%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3ALowerBoundary%3E%3Cogc%3AUpperBoundary%3E%3Cogc%3ALiteral%3E4737%3C%2Fogc%3ALiteral%3E%3C%2Fogc%3AUpperBoundary%3E%3C%2Fogc%3APropertyIsBetween%3E%3C%2Fogc%3AFilter%3E%3Csld%3APolygonSymbolizer%3E%3Csld%3AFill%3E%3Csld%3ACssParameter%20name%3D%22fill%22%3E%23C46D1B%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22fill-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AFill%3E%3Csld%3AStroke%3E%3Csld%3ACssParameter%20name%3D%22stroke%22%3E%2333FF00%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-opacity%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-width%22%3E1%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linejoin%22%3Eround%3C%2Fsld%3ACssParameter%3E%3Csld%3ACssParameter%20name%3D%22stroke-linecap%22%3Eround%3C%2Fsld%3ACssParameter%3E%3C%2Fsld%3AStroke%3E%3C%2Fsld%3APolygonSymbolizer%3E%3C%2Fsld%3ARule%3E%3C%2Fsld%3AFeatureTypeStyle%3E%3C%2Fsld%3AUserStyle%3E%3C%2Fsld%3ANamedLayer%3E%3C%2Fsld%3AStyledLayerDescriptor%3E&BBOX=-122.64942090625,37.6087920625,-122.25391309375,37.8724639375&WIDTH=1152&HEIGHT=768

Response to sample request 3

Response to Sample Request 3

3/6/2013