Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Hillshade renderer

Sample Viewer View Sample on GitHub

Apply a hillshade renderer to a raster.

Use case

An environmental agency may track coastal erosion by comparing images of an area taken over a a longer period of time with hillshade renderers applied.

How to use the sample

Choose and adjust the settings to update the hillshade renderer on the raster layer. The sample allows you to change the Altitude, Azimuth, and Slope Type.

How it works

A Raster is constructed from the local raster file. The Raster is then used to construct a RasterLayer, which is then added to a Map. Finally HillshadeRenderer is created, several of the properties are set (azimuth, angle, and so on), and the renderer is set on the RasterLayer. You can modify the look of the HillshadeRenderer by pressing the Edit Renderer button, and changing the azimuth, angle, and slope type. Each time the apply button is clicked, a new HillshadeRenderer is created and set on the RasterLayer.

  1. Create a Raster from a grayscale raster file.
  2. Create a RasterLayer from the raster.
  3. Create a Basemap from the raster layer and set it to the map.
  4. Create a HillshadeRenderer, specifying the slope type and other properties.
  5. Set the hillshade renderer to be used on the raster layer with rasterLayer.renderer.

Relevant API

  • Basemap
  • HillshadeRenderer
  • Raster
  • RasterLayer

Offline Data

Read more about how to set up the sample's offline data here.

Link Local Location
Hillshade raster <userhome>/ArcGIS/Runtime/Data/raster/srtm.tiff

Tags

altitude, angle, azimuth, raster, slope, visualization

Sample Code

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600
    
    readonly property url dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/raster"
    
    MapView {
        id: mapView
        anchors.fill: parent

        //! [HillshadeRenderer QML apply to layer snippet]
        Map {
            Basemap {
                // add a raster to the basemap
                RasterLayer {
                    id: rasterLayer

                    Raster {
                        path: dataPath + "/srtm.tiff"
                    }

                    // declare a HillshadeRaster as a child of RasterLayer,
                    // as renderer is a default property of RasterLayer
                    HillshadeRenderer {
                        altitude: 45
                        azimuth: 315
                        zFactor: 0.000016
                        slopeType: Enums.SlopeTypeNone
                        pixelSizeFactor: 1
                        pixelSizePower: 1
                        outputBitDepth: 8
                    }
                }
            }
            //! [HillshadeRenderer QML apply to layer snippet]

            onLoadStatusChanged: {
                if (loadStatus === Enums.LoadStatusLoaded) {
                    mapView.setViewpointScale(754479);
                }
            }
        }
    }

    Button {
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: parent.bottom
            bottomMargin: 25
        }
        text: "Edit Renderer"
        onClicked: hillshadeSettings.visible = true;
    }

    HillshadeSettings {
        id: hillshadeSettings
        anchors.fill: parent
    }

    function applyHillshadeRenderer(altitude, azimuth, slope) {
        // create the new renderer
        const hillshadeRenderer = ArcGISRuntimeEnvironment.createObject("HillshadeRenderer", {
                                                                            altitude: altitude,
                                                                            azimuth: azimuth,
                                                                            zFactor: 0.000016,
                                                                            slopeType: slope,
                                                                            pixelSizeFactor: 1,
                                                                            pixelSizePower: 1,
                                                                            outputBitDepth: 8
                                                                        });

        // set the renderer on the layer
        rasterLayer.renderer = hillshadeRenderer;
    }
}
import QtQuick 2.5
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Esri.ArcGISRuntime 100.9

Rectangle {
    id: root
    color: "transparent"
    visible: false

    RadialGradient {
        anchors.fill: parent
        opacity: 0.7
        gradient: Gradient {
            GradientStop { position: 0.0; color: "lightgrey" }
            GradientStop { position: 0.7; color: "black" }
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: mouse.accepted = true
        onWheel: wheel.accepted = true
    }

    Rectangle {
        anchors.centerIn: parent
        width: childrenRect.width
        height: childrenRect.height
        color: "lightgrey"
        radius: 5
        border {
            color: "#4D4D4D"
            width: 1
        }

        GridLayout {
            columns: 2

            Text {
                Layout.margins: 5
                Layout.columnSpan: 2
                Layout.alignment: Qt.AlignHCenter
                text: "Hillshade Renderer Settings"
                font.weight: Font.DemiBold
            }

            Text {
                Layout.margins: 5
                text: "Altitude"
            }

            Slider {

                id: altitudeSlider
                Layout.margins: 5
                from: 0
                to: 90
            }

            Text {
                Layout.margins: 5
                text: "Azimuth"
            }

            Slider {
                id: azimuthSlider
                Layout.margins: 5
                from: 0
                to: 360
            }

            Text {
                Layout.margins: 5
                text: "Slope"
            }

            ComboBox {
                id: slopeBox
                property int modelWidth: 0
                Layout.minimumWidth: modelWidth + leftPadding + rightPadding + indicator.width
                Layout.margins: 5
                Layout.fillWidth: true
                model: HillshadeSlopeTypeModel{}
                textRole: "name"


                Component.onCompleted : {
                    for (let i = 0; i < model.count; ++i) {
                        metrics.text = model.get(i).name;
                        modelWidth = Math.max(modelWidth, metrics.width);
                    }
                }
                TextMetrics {
                    id: metrics
                    font: slopeBox.font
                }
            }


            Button {
                Layout.margins: 5
                Layout.columnSpan: 2
                Layout.alignment: Qt.AlignHCenter
                text: "Apply"
                onClicked: {
                    const altitude = altitudeSlider.value;
                    const azimuth = azimuthSlider.value;
                    const slope = slopeBox.model.get(slopeBox.currentIndex).value;
                    applyHillshadeRenderer(altitude, azimuth, slope);
                    root.visible = false;
                }
            }
        }
    }
}
import QtQuick 2.5
import Esri.ArcGISRuntime 100.9

ListModel {
    ListElement {
        name: "None"
        value: Enums.SlopeTypeNone
    }
    ListElement {
        name: "Degree"
        value: Enums.SlopeTypeDegree
    }
    ListElement {
        name: "Percent Rise"
        value: Enums.SlopeTypePercentRise
    }
    ListElement {
        name: "Scaled"
        value: Enums.SlopeTypeScaled
    }
}