2

I am working with MapServer WMS in the form of mapfiles and consuming them into a OpenLayers map.

I am trying to find out a way to ease the symbolization process of the various layers in a mapfile.

I have not started diving into the STYLE directive yet, but before I do that I'd like to know whether there's an easy way to (let's say) preview the style of my layers (an application?) and export it into a (e.g.) SLD which the MapServer can read.

I don't know if this is the best (or feasible) way to go about styling mapfile's layers, but I am open to any kind of suggestion.

3

As MapServer doesn't deal internally with SLD's, any SLD's given to it externally have to be parsed before being applied, unless you already have a tool for creating SLD, using SLD's with MapServer for providing the default styling is probably not the way to go. I would just use SLD's just for creating custom maps as the result of some on-the-fly query only.

Probably it would be better to look for tools that generate the MapServer style for you, such as MapManager from GISInternals

4

You can't use SLD to internally style a MapServer WMS map, you'll have to use the STYLE directives.

However

MapServer will take an SLD as part of a GetMap request, either by reference (you link to a URL of the SLD), using the SLD=[your link to your SLD]& parameter or directly as part of the SLD_BODY=[your SLD]& parameter.

You can review this in a browser.

Exercise

Consider a MapServer WMS providing radon information.

A GetMap request using the default style might look like:

http://ogc.bgs.ac.uk/cgi-bin/BGS_BGS-HPA_Radon_Potential/wms?language=eng&VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=50.179445759563,-4.41340973640857,50.9615344710795,-3.2834397199341&WIDTH=877&HEIGHT=607&LAYERS=GBR_BGS-HPA_625K_RADON_POTENTIAL&STYLES=&EXCEPTIONS=XML&FORMAT=image/png&BGCOLOR=0xFEFFFF&TRANSPARENT=TRUE&

Giving a map like:

GetMap default style

The map file definition of the style is:

    CLASS
        # Dummy for legend title
        MINSCALEDENOM 250000
        NAME "Bq m3"
        EXPRESSION ""
        STYLE
            COLOR 255 255 255
        END
    END
    CLASS
        MINSCALEDENOM 250000
        NAME "> 499.99"
        EXPRESSION ">499.99"
        STYLE
            COLOR 255 0 0
        END
    END
    CLASS
        MINSCALEDENOM 250000
        NAME "200 - 499.99"
        EXPRESSION "200 - 499.99"
        STYLE
            COLOR 230 152 0
        END
    END
    CLASS
        MINSCALEDENOM 250000
        NAME "100 - 199.99"
        EXPRESSION "100 - 199.99"
        STYLE
            COLOR 255 255 0
        END
    END
    CLASS
        MINSCALEDENOM 250000
        NAME "50 - 99.99"
        # EXPRESSION "50 - 99.99"
        EXPRESSION "[50 - 99.99]"
        STYLE
            COLOR 190 210 255
        END
    END
    CLASS
        MINSCALEDENOM 250000
        NAME "20 - 49.99"
        EXPRESSION "20 - 49.99"
        STYLE
            COLOR 0 112 255
        END
    END
    CLASS
        MINSCALEDENOM 250000
        NAME "< 20"
        EXPRESSION "< 20"
        STYLE
            COLOR 0 77 168
        END
    END

But a general user can't see this. A user though can make a GetStyles request like:

http://ogc.bgs.ac.uk/cgi-bin/BGS_BGS-HPA_Radon_Potential/wms?version=1.3.0&service=WMS&request=GetStyles&sld_version=1.1.0&layers=GBR_BGS-HPA_625K_RADON_POTENTIAL&STYLE=default&

Which is MapServers effort at converting the internal style to SLD, so here it gives us:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <NamedLayer>
        <se:Name>GBR_BGS-HPA_625K_RADON_POTENTIAL</se:Name>
        <UserStyle>
            <se:FeatureTypeStyle>
                <se:Rule>
                    <se:Name>Bq m3</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal></ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#ffffff</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
                <se:Rule>
                    <se:Name>&gt; 499.99</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal>>499.99</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#ff0000</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
                <se:Rule>
                    <se:Name>200 - 499.99</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal>200 - 499.99</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#e69800</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
                <se:Rule>
                    <se:Name>100 - 199.99</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal>100 - 199.99</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#ffff00</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
                <se:Rule>
                    <se:Name>50 - 99.99</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal>50 - 99.99</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#bed2ff</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
                <se:Rule>
                    <se:Name>20 - 49.99</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal>20 - 49.99</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#0070ff</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
                <se:Rule>
                    <se:Name>&lt; 20</se:Name>
                    <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>AM_GFRn</ogc:PropertyName><ogc:Literal>&lt; 20</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>
                    <se:MinScaleDenominator>250000.000000</se:MinScaleDenominator>
                    <se:PolygonSymbolizer>
                        <se:Fill>
                            <se:SvgParameter name="fill">#004da8</se:SvgParameter>
                        </se:Fill>
                    </se:PolygonSymbolizer>
                </se:Rule>
            </se:FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>

We could take this style, modify it, put it on a server, and request it as part of a GetMap request like:

http://ogc.bgs.ac.uk/cgi-bin/BGS_BGS-HPA_Radon_Potential/wms?language=eng&VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=50.179445759563,-4.41340973640857,50.9615344710795,-3.2834397199341&WIDTH=877&HEIGHT=607&LAYERS=GBR_BGS-HPA_625K_RADON_POTENTIAL&STYLES=&EXCEPTIONS=XML&FORMAT=image/png&BGCOLOR=0xFEFFFF&TRANSPARENT=TRUE&sld=http://ogc.bgs.ac.uk/sld/radon1.sld&

Giving us:

GetMap external style

  • That sounds promising. Do you know if QGIS, uDIG or whatever freeGIS software (or in a broad sense, whathever free application) can produce (export) valid SLDs? And, can you maybe provide a link to understand the link between the SLD file and the layers in the mapfile? Thanks in advance for your precious help! – umbe1987 May 3 '18 at 14:19
  • 2
    MapServer can export SLD, that's what the GetStyles operation does, it generates the SLD from the internal style, it largely works except if you define symbols in MapServer. If you don't already have a tool for generating your own SLD, it seems a slightly odd to want to create one to pass to MapServer for default styling because MapServer will have to parse it before applying it, and it would be faster to use the internal mechanism (it's actually very powerful when you get into it. OTOH if you want to query the map data and create custom maps on the fly then generating SLDs is the way to go. – nmtoken May 3 '18 at 15:36
  • 1
    It's not really the question you asked, but you could look at gisinternals.com/MapManager which will I think generate MapServer styles – nmtoken May 3 '18 at 15:47
  • Ok, I think I got the point now. As my intent was to ease the preparation of the symbols by means of an application that could preview the result and eventually write it in the form of a mapfile, I guess the MapManager is probably what I should look into. I also noticed there's a github page about MapFile editors, which I should look into as well. Actually, the SLD way was just my guess from an ignorant perspective. MapFile Editors are closer to my ideal siolution. Should you turn your comments to answer, I'd be happy to accept it. – umbe1987 May 3 '18 at 15:55

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.