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

Adding hillshade

  1. Open a shell (CTRL+ALT+T) and run:

    cd /home/unredd/geoserver_data/data/boulder
    
    gdaldem hillshade -z 5 -s 111120 srtm_boulder.tiff srtm_boulder_hs.tiff -co tiled=yes
    

    Note

    The z parameter exxagerates 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.

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

  3. 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" opacity="0.7" quantity="1.0"/>
                                <sld:ColorMapEntry color="#FFFFFF" opacity="0.7" quantity="256.0"/>
                            </sld:ColorMap>
                        </sld:RasterSymbolizer>
                    </sld:Rule>
                </sld:FeatureTypeStyle>
            </sld:UserStyle>
        </sld:UserLayer>
    </sld:StyledLayerDescriptor>
    

    Note

    Note the opacity values being less than 1, in order to made it partially transparent which will allows to do overlaying on other layers

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

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

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

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

  8. 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 /home/unredd/geoserver_data/data/boulder

  9. Click Save.

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

    ../../_images/raster_hillshade.png

    Publishing Raster Layer

  11. Set SRTM Hillshade as Title

  12. Switch to Publishing tab

    ../../_images/raster_hillshade_publishing.png
  13. Make sure to set the default style to hillshade on the Publishing –> Default Style section.

    ../../_images/raster_hillshade_defaultstyle.png

    Editing Raster Publishing info

  14. Click Save to create the new layer.

  15. 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

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

    ../../_images/raster_overlay_url.png
  17. Insert the geosolutions:srtm, additional layer (note the final comma) before the geosolutions:hillshade one

    ../../_images/raster_overlay_2layers.png
  18. 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