I had the perfect hillshade raster ready to throw on top of my web map, I had previewed it in QGIS and the colour stretching and values looked fine.
I then loaded it into GeoServer and it looked great in the OpenLayers Layer Preview window as well.
However, once I added it as a WMS layer in a Leaflet map, I got really confused. Even though I had my NODATA=255 parameters seemingly working well there appeared a small strip around the outside of the image that was obnoxious.

I figured I could change it with an SLD but hadn’t done it before so it took a while to figure out. For a couple hours I tried various permutations of the default “raster” Style, but with no luck. The image, otherwise, looked great so the Style obviously wasn’t a real problem in and of itself.
The trick came when I realised that I need to set my color maps for the gray band explicitly. Up to this point no particular band had been isolated for color mapping. I found the right place to put the elements in the SLD and all worked out well.
My takeaway: there must be a better way to develop SLD for rasters. The options in the GeoServer docs are amazing and exciting, but trying to fit them into a specific context has always been a challenge for me. That’s why I had to write this down, but I’m sure I’ll have to remember it all again a year from now!

My SLD:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?xml version="1.0" encoding="ISO-8859-1"?> <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 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"> <NamedLayer> <Name>default_hillshade</Name> <UserStyle> <Title>Raster Hillshade</Title> <Abstract>Grayscale hillshade SLD</Abstract> <FeatureTypeStyle> <Rule> <Name>rule1</Name> <Title>Hillshade with transparency</Title> <Abstract>Ignore values outside valid range, nodata values transparent</Abstract> <RasterSymbolizer> <ChannelSelection> <GrayChannel> <SourceChannelName>1</SourceChannelName> </GrayChannel> </ChannelSelection> <ColorMap> <ColorMapEntry color="#000000" quantity="1" label="low" opacity="1"/> <ColorMapEntry color="#FFFFFF" quantity="254" label="high" opacity="1"/> <ColorMapEntry color="#FFFFFF" quantity="255" label="alpha" opacity="0"/> </ColorMap> </RasterSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor> |