Trick serving a hillshade image from GeoServer

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.
Hillshade in QGIS

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.

When GeoServer skews the image it creates a region around the image that has value=0.  This image already had nodata=255, so it can be very confusing.
When GeoServer skews the image it creates a region around the image that has value=0. This image already had nodata=255, so it can be very confusing.

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!

Note there is no skewed "collar" around the image as value=0 is ignored.
Note there is no skewed “collar” around the image as value=0 is ignored.

 
My SLD:



  
    default_hillshade
    
      Raster Hillshade
      Grayscale hillshade SLD
      
        
          rule1
          Hillshade with transparency
          Ignore values outside valid range, nodata values transparent
          
          	
            	
                	1
               	                          
            
	        
            	
                
                     
			
          
        
      
    
  

 

 

Published by

Tyler Mitchell

Product and marketing leader, author and technology writer in NoSQL, big data, graph analytics, and geospatial. Follow me @1tylermitchell or get my book from http://locatepress.com/gpt

One thought on “Trick serving a hillshade image from GeoServer”

Comments are closed.

WordPress Appliance - Powered by TurnKey Linux