Tutorial

Style Rasters in Geoserver

Summary

This tutorial explains how to style a raster layer in Geoserver, from exporting an SLD from QGIS to previewing the styled raster in Geoserver.

Introduction

Most single and multi-band rasters, such RGB imagery, will visualize as they should in Geoserver without further styling required. However, for rasters that are styled with palette/unique values or specific colour ramps, you will need to export the style from QGIS as a Styled Layer Descriptor (SLD) file, upload it to Geoserver, and apply the style to the Geoserver raster layer. The following instructions outline one of many ways to style a raster layer in Geoserver. 

1. Style a Raster Layer in Geoserver

  1. In QGIS, load the source imagery. Make sure to load a copy of the exact same raster that was loaded into Geoserver. 
  2. Style the raster in QGIS as desired. 
  3. Open the layer properties, click on the Symbology section, and on the bottom click on Style > Save Style…
  4. In the Save Layer Style dialog box, set the following parameters:
    • Save style: As SLD Style File
    • File: set output location with .sld extension. 
    • Click OK.
  5. Log into Geoserver and on the left menu, click on Styles
  6. Click “Add a new style”
  7.  On the New Style page, click the “Choose file” button and locate the SLD file that you created in Step 4. Once located, click Upload…
  8. The SLD file will upload and the XML will appear in the large text box. 
  9. The style Name will be automatically taken from the file name. Change it, if required. 
  10. Click the Preview legend button to make sure it is correct. 
  11. Modify the SLD parameters in the XML file, if required (e.g. add more space between the legend graphic and the legend text). 
  12. Click the Validate button to make sure there are no errors in the SLD file. 
  13. If successful, click the Save button. 
  14. On the left menu, click on Data > Layers  and then click on the layer that requires the new style to be applied. 
  15. In the Edit Layer page, click on the Publishing tab at the top, then scroll down to the WMS Settings. Here you will see the Default Style applied to the image (usually called ‘raster’ for imagery).
  16. Change the default style to the style you just created. 
  17. Click Save. 
  18. On the Geoserver left menu, click on Data > Layer Preview and preview the layer that should have the new style applied. 
  19. What if the image does not appear? Here are some troubleshooting tips:
    • There could be something wrong with the style. Go back into the style definition and make sure you can preview the legend. Also try validating the SLD. 
    • The SLD may have been produced with an incompatible version. If QGIS changes its SLD version, this workflow may break. 
    • The Geoserver documentation on Styles and SLDs is very thorough. Check the documentation if there is no clear resolution. 
    • Alternatively, you may also try to style layers using CSS. There is a Geoserver plugin.

2. What if the image does not preview as expected?

Here are some troubleshooting tips:

  • There could be something wrong with the style. Go back into the style definition and make sure you can preview the legend. Also try validating the SLD. 
  • The SLD may have been produced with an incompatible version. If QGIS changes its SLD version, this workflow may break. 
  • The Geoserver documentation on Styles and SLDs is very thorough. Check the documentation if there is no clear resolution. 
  • Alternatively, you may also try to style layers using CSS. There is a Geoserver plugin.

How can we help?

Contact us today to schedule a free consultation with a member of our team.

    captcha