5.7. WMS layers use SLD#
By using SLD, the style of the map can be modified dynamically.
This page describes the process of leveraging Styled Layer Descriptor
(SLD) support in WMS Getmap
requests using Mapserver. SLD supports
both server-side (ability to read SLD and apply it with getmap
requests) and client-side (including sending SLD requests to the server
and dynamically generating SLD files from the map server’s Mapfile). SLD
support was added to MapServer in version 4.2.
5.7.1. Definition and effect of SLD#
SDL is defined using the XML format. Let’s take a look at the example:
1<?xml version="1.0" encoding="UTF-8"?>
2<StyledLayerDescriptor version="1.0.0"
3 xmlns="http://www.opengis.net/sld"
4 xmlns:ogc="http://www.opengis.net/ogc"
5 xmlns:xlink="http://www.w3.org/1999/xlink"
6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7 xsi:schemaLocation="http://www.opengis.net/sld
8 http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
9 <NamedLayer>
10 <Name>states</Name>
11 <UserStyle>
12 <Title>xxx</Title>
13 <FeatureTypeStyle>
14 <Rule>
15 <LineSymbolizer>
16 <Geometry>
17 <ogc:PropertyName>center-line</ogc:PropertyName>
18 </Geometry>
19 <Stroke>
20 <CssParameter name="stroke">#0000ff</CssParameter>
21 </Stroke>
22 </LineSymbolizer>
23 </Rule>
24 </FeatureTypeStyle>
25 </UserStyle>
26 </NamedLayer>
27</StyledLayerDescriptor>
Effect:
Get a partial map with GetMap
The URL is parsed as follows:
>>> [print(idx, x) for idx, x in enumerate(url.split('&'))]
0 http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb2.map
1 SERVICE=WMS
2 VERSION=1.3.0
3 REQUEST=GetMAP
4 LAYERS=states
5 BBOX=73,3,136,54
6 CRS=CRS:84
7 INFO_FORMAT=text/html
8 format=image/png
9 width=200
10 height=150
11 styles=
12 SLD=http://webgis.pub/sld_world_lyr.xml
5.7.2. Definition and effect of SLD 1.1.0#
The definition of SLD version 1.1.0 is not quite the same as the latest version.
1<?xml version="1.0" encoding="UTF-8"?>
2<StyledLayerDescriptor version="1.1.0"
3 xmlns="http://www.opengis.net/sld"
4 xmlns:se="http://www.opengis.net/se"
5 xmlns:ogc="http://www.opengis.net/ogc"
6 xmlns:xlink="http://www.w3.org/1999/xlink"
7 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8 xsi:schemaLocation="http://www.opengis.net/sld
9 http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd">
10 <NamedLayer>
11 <se:Name>states</se:Name>
12 <UserStyle>
13 <se:Name>country</se:Name>
14 <se:FeatureTypeStyle>
15 <se:Rule>
16 <se:Name>country-rule1</se:Name>
17 <se:PolygonSymbolizer>
18 <se:Geometry>
19 <ogc:PropertyName>center-line2</ogc:PropertyName>
20 </se:Geometry>
21 <se:Fill>
22 <se:SvgParameter name="fill">#e8e8e8</se:SvgParameter>
23 </se:Fill>
24 <se:Stroke>
25 <se:SvgParameter name="stroke">#0000ff</se:SvgParameter>
26 <se:SvgParameter name="stroke-width">3</se:SvgParameter>
27 </se:Stroke>
28 </se:PolygonSymbolizer>
29 </se:Rule>
30 </se:FeatureTypeStyle>
31 </UserStyle>
32 </NamedLayer>
33 <NamedLayer>
34 <se:Name>states_line</se:Name>
35 <UserStyle>
36 <se:Name>country</se:Name>
37 <se:FeatureTypeStyle>
38 <se:Rule>
39 <se:Name>country-rule1</se:Name>
40 <se:LineSymbolizer>
41 <se:Geometry>
42 <ogc:PropertyName>center-line</ogc:PropertyName>
43 </se:Geometry>
44 <se:Stroke>
45 <se:SvgParameter name="stroke">#ff0000</se:SvgParameter>
46 </se:Stroke>
47 </se:LineSymbolizer>
48 </se:Rule>
49 </se:FeatureTypeStyle>
50 </UserStyle>
51 </NamedLayer>
52</StyledLayerDescriptor>
Effect:
Get a partial map with GetMap
The URL is parsed as follows:
>>> [print(idx, x) for idx, x in enumerate(url.split('&'))]
0 http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb2.map
1 SERVICE=WMS
2 VERSION=1.3.0
3 REQUEST=GetMAP
4 LAYERS=states
5 BBOX=73,3,136,54
6 CRS=CRS:84
7 INFO_FORMAT=text/html
8 format=image/png
9 width=200
10 height=150
11 styles=
12 SLD=http://webgis.pub/sld_world_lyr110.xml