[MapServer-users] How to use SLD generated from CLASS and how to use STYLEITEM with sld

Trygve Aspenes trygve at aspenes.priv.no
Thu May 8 04:21:13 PDT 2025


I'm looking at SLD with mapserver 8.4.0

I think I read somewhere in the docs that mapserver can generate SLD 
from a layer defined class. Not sure if this is correct. I try with my 
test with GetStyles like this:

curl 
'http://localhost:8091/okd?version=1.3.0&service=wms&request=getstyles&layers=TestLayer'

But this gives me:

<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">
</StyledLayerDescriptor>

So it is a valid SLD, but with no actual content

The layer part in my mapfile looks like this:
     LAYER
         NAME "TestLayer"
         TYPE RASTER
         STATUS ON
         METADATA
             "ows_sld_enabled" "true"
             "SLD_USE_FIRST_NAMEDLAYER" "true"
         END
         DATA "<raster data>"
         PROJECTION
            <some projection>
         END
         METADATA
             "wms_title" "Test Layer"
             "wms_srs" "EPSG:3857 EPSG:4326"
         END
         CLASS
             NAME " 0 -  3"
             GROUP "value"
             EXPRESSION ([pixel]>=0.0 and [pixel]<3.0)
             STYLE
                 COLOR 221 95 77
             END # STYLE
         END # CLASS
         <Some more classes>
      END


Then I try to remove the CLASS definitions and add STYLEITEM with and 
sld document like this:

     LAYER
         NAME "TestLayer"
         TYPE RASTER
         STATUS ON
         STYLEITEM "sld://sld-test.xml" #Using the example of the latest 
docs p 873-874>
         METADATA
             "ows_sld_enabled" "true"
             "SLD_USE_FIRST_NAMEDLAYER" "true"
         END
         DATA "<raster data>"
         PROJECTION
            <some projection>
         END
         METADATA
             "wms_title" "Test Layer"
             "wms_srs" "EPSG:3857 EPSG:4326"
         END
      END

But still the same response with the GetStyles request as above.

What am I missing here? Any ideas?

mapserv -v says: MapServer version 8.4.0 PROJ version 9.4 GDAL version 
3.8 OUTPUT=PNG OUTPUT=JPEG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE 
SUPPORTS=CAIRO SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER 
SUPPORTS=WFS_SERVER SUPPORTS=WCS_SERVER SUPPORTS=OGCAPI_SERVER 
SUPPORTS=FASTCGI SUPPORTS=GEOS SUPPORTS=PBF INPUT=JPEG INPUT=POSTGIS 
INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE INPUT=FLATGEOBUF

Trygve


More information about the MapServer-users mailing list