Styling Raster data

In the previous section we have created and optimized some vector styles. In this section we will deal with a styled SRTM raster and we will see how to get a better visualization of that layer by adding hillshade.

  1. From the Welcome Page navigate to Layer Preview and select the OpenLayers link for the geosolutions:srtm layer.


    SRTM rendering with DEM style

    There is a DEM style associated to that SRTM dataset layer, resulting in such a colored rendering.

  2. Return to the GeoServer Welcome Page, select the Styles and click the dem style to see which color map is applied.


    You have to be logged in as Administrator in order to edit/check styles.


    Style editing

    Note the entries with opacity = 0.0 which allow to make no data values as transparent.

The current DEM style allows to get a pleasant rendering of the SRTM dataset but we can get better results by combining it with an hillshade layer which will be created through another GDAL utility (gdaldem).


The CSS equivalent of this style is the following

[@scale > 75000] {
  raster-channels: auto;
    color-map-entry(#00BFBF, -100.0, 0)
    color-map-entry(#00FF00, 920.0, 0)
    color-map-entry(#00FF00, 920.0, 1.0)
    color-map-entry(#FFFF00, 1940.0, 1.0)
    color-map-entry(#FFFF00, 1940.0, 1.0)
    color-map-entry(#FF7F00, 2960.0, 1.0)
    color-map-entry(#FF7F00, 2960.0, 1.0)
    color-map-entry(#BF7F3F, 3980.0, 1.0)
    color-map-entry(#BF7F3F, 3980.0, 1.0)
    color-map-entry(#141514, 5000.0, 1.0);

Adding hillshade

  1. If on Linux, open a shell and run:

    gdaldem hillshade -z 5 -s 111120 ${TRAINING_ROOT}/geoserver_data/data/boulder/srtm_boulder.tiff ${TRAINING_ROOT}/geoserver_data/data/boulder/srtm_boulder_hs.tiff -co tiled=yes
  2. If on Windows instead, open the TRAINING_ROOT/gdal folder, launch the SDKShell.bat file and run:

    gdaldem hillshade -z 5 -s 111120 %TRAINING_ROOT%\geoserver_data\data\boulder\srtm_boulder.tiff %TRAINING_ROOT%\geoserver_data\data\boulder\srtm_boulder_hs.tiff -co tiled=yes


    The z parameter exaggerates the elevation, the s parameter provides the ratio between the elevation units and the ground units (degrees in this case), -co tiled=yes makes gdaldem generate a TIFF with inner tiling. We’ll investigate this last option better in the following pages.

  3. From the Welcome Page navigate to Styles and select Add a new style as previously seen in the Adding a style section.

  4. In the SLD Editor enter the following XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <sld:StyledLayerDescriptor xmlns="" xmlns:sld="" xmlns:ogc="" xmlns:gml="" version="1.0.0">
                  <sld:ColorMapEntry color="#000000" opacity="0.0" quantity="0.0"/>
                  <sld:ColorMapEntry color="#999999" quantity="1.0"/>
                  <sld:ColorMapEntry color="#FFFFFF" quantity="256.0"/>
            <sld:VendorOption name="composite">multiply</sld:VendorOption>


    The CSS equivalent of this style is the following

    [@scale > 75000] {
      raster-channels: auto;
        color-map-entry(#000000, 0, 0)
        color-map-entry(#999999, 1)
        color-map-entry(#FFFFFF, 256);
      composite: 'multiply';


    Note the “composite” vendor option, used to have the hillshading use a special color blending mode to get a better visual result compared to simple translucency

  5. Set hillshade as name and then click the Submit button.

  6. Select Add stores from the GeoServer Welcome Page to add the previously created hillshade raster.

  7. Select GeoTIFF - Tagged Image File Format with Geographic information from the set of available Raster Data Sources.

  8. Specify hillshade as name in the Data Source Name field of the interface.

  9. Click on browse link in order to set the GeoTIFF location in the URL field.


    make sure to specify the srtm_boulder_hs.tiff previously created with gdaldem, which should be located at $TRAINING_ROOT/geoserver_data/data/boulder ( %TRAINING_ROOT%\geoserver_data\data\boulder on windows )

  10. Click Save.

  11. Publish the layer by clicking on the publish link.


    Publishing Raster Layer

  12. Set hillshade as the name

  13. Switch to Publishing tab

  14. Make sure to set the default style to hillshade on the Publishing –> Default Style section.


    Editing Raster Publishing info

  15. Click Save to create the new layer.

  16. Use the Layer Preview to preview the new layer with the hillshade style.


    Previewing the new raster layer with the hillshade style applied

  17. Edit the Layer Preview URL in your browser by locating the layers parameter

  18. Insert the geosolutions:srtm, additional layer (note the final comma) before the geosolutions:hillshade one:

  19. Press Enter to send the updated request. The Layer Preview should change like this where you can see both the srtm and hillshade layers.


    Layer preview with srtm and hillshade being overlaid