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.

    ../_images/raster_srtm.png

    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.

    Note

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

    ../_images/raster_dem_style.png

    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 a hillshade layer which will be created through another GDAL utility (gdaldem).

Note

The CSS equivalent of this style is the following

[@scale > 75000] {
  raster-channels: auto;
  raster-color-map:
    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 folder, launch the OSGeo4W.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
    

    Note

    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="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
      <sld:UserLayer>
        <sld:LayerFeatureConstraints>
          <sld:FeatureTypeConstraint/>
        </sld:LayerFeatureConstraints>
        <sld:UserStyle>
          <sld:Title/>
          <sld:FeatureTypeStyle>
            <sld:Name>name</sld:Name>
            <sld:FeatureTypeName>Feature</sld:FeatureTypeName>
            <sld:Rule>
              <sld:MinScaleDenominator>75000</sld:MinScaleDenominator>
              <sld:RasterSymbolizer>
                <sld:Geometry>
                  <ogc:PropertyName>grid</ogc:PropertyName>
                </sld:Geometry>
                <sld:ColorMap>
                  <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:ColorMap>
              </sld:RasterSymbolizer>
            </sld:Rule>
            <sld:VendorOption name="composite">multiply</sld:VendorOption>
          </sld:FeatureTypeStyle>
        </sld:UserStyle>
      </sld:UserLayer>
    </sld:StyledLayerDescriptor>
    

    Note

    The CSS equivalent of this style is the following

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

    Note

    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.

    Note

    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.

    ../_images/raster_hillshade.png

    Publishing Raster Layer

  12. Set hillshade as the name

  13. Switch to Publishing tab

    ../_images/raster_hillshade_publishing.png

    Raster Layer - Publishing tab

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

    ../_images/raster_hillshade_defaultstyle.png

    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.

    ../_images/raster_hillshade_preview.png

    Previewing the new raster layer with the hillshade style applied

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

    ../_images/raster_overlay_url.png

    Edition of URL

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

    ../_images/raster_overlay_2layers.png

    Edition of URL - Additional layer on list

  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.

    ../_images/raster_overlay.png

    Layer preview with srtm and hillshade being overlaid