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
               	                          
            
	        
            	
                
                     
			
          
        
      
    
  

 

 

Geospatial Power Tools Reviews [Book]

Thinking of buying my latest book?  We’ve finally got a few reviews on Amazon that might help you decide.  See my other post for more about the book.  Buy the PDF on Locate Press.com.

Reader Reviews

Geospatial Power Tools book cover
From Amazon.com

5.0 out of 5 stars This book makes a great reference manual for using GDAL/OGR suite of command line …,
January 24, 2015 By Leo Hsu
“The GDAL Toolkit is chuckful of ETL commandline tools for working with 100s of spatial (and not so spatial data sources). Sadly the GDAL website only provides the basic API command switches with very few examples to get a user going with. I was really excited when this book was announced and purchased as soon as it came out. This book makes a great reference manual for using GDAL/OGR suite of command line utilities.
Several chapters are devoted to each commandline tool, explaining what its for, the switches it has, and several examples of how to use each one. You’ll learn how to work with both vector/(basic data no vector) data sources and how to convert from one vector format to another. You’ll also learn how to work with raster data and how to transform from one raster data source to another as well as various operations you can perform on these.”

 

“This is a great book for any GIS pro to get their hands dirty and learn how to use spatial tools to do some amazing things. The benefit of using the tools covered in this book (GDAL/OGR) is that you could learn to integrate these tools into other workflows, such as downloading the latest raster data for your organization on weekly basis and running the necessary tools against it.
The first part of the book is filled with some great examples to get you familiar with using these tools and the rest of the book covers the documentation of these tools in detail. This should be on every GIS pros bookshelf.”

 

Amazon UK:

5.0 out of 5 stars Absolute Must Have Reference.
14 Feb. 2015 By SamFranklin
“I have been a GDAL/OGR user for about 3 years and have always struggled to find readable, entry-level GDAL documentation that provides simple examples which are well explained. This I feel this is a barrier to greater adoption of GDAL/OGR.
This book 100% fills this gap and is therefore required reading for GDAL novices and veterans alike. The book is split between “Common Tasks & Workflows” and then a comprehensive guide to all utilities. I read it cover to cover and picked a number of ideas and solutions to problems with existing workflows involving GDAL, for that alone, it’s easily worth buying. The first chapter provides links to sample data which is used throughout the book. This allows the reader to replicate every example which is great for learning trickier and lesser known utilities.Cannot recommend highly enough. Great job.”
Thanks for reading, reviewing and for the encouraging comments guys.

Follow me on Twitter and follow Locate Press too for latest sales and deals!  Want to write a book too?  Contact me to discuss.

 

WordPress Appliance - Powered by TurnKey Linux