View on GitHub Sample viewer app

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

  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, new HillshadeRenderer(Altitude, Azimuth, ZFactor, SlopeType, PixelSizeFactor, PixelSizePower, OutputBitDepth).
  5. Set the hillshade renderer to be used on the raster layer with rasterLayer::setRenderer(renderer).

Relevant API

  • Basemap
  • HillshadeRenderer
  • Raster
  • RasterLayer

Offline Data

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

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

Tags

altitude, angle, azimuth, raster, slope, visualization

Sample Code

HillshadeSettings.qml HillshadeSettings.qml HillshadeSlopeTypeModel.qml Hillshade_Renderer.cpp Hillshade_Renderer.h Hillshade_Renderer.qml main.cpp
// [WriteFile Name=Hillshade_Renderer, Category=Layers]
// [Legal]
// Copyright 2016 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Esri.Samples
Rectangle {
id: root
color: "transparent"
visible: false
Rectangle {
anchors.fill: parent
color: "#60000000"
}
MouseArea {
anchors.fill: parent
onClicked: mouse => mouse.accepted = true
onWheel: wheel => 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 ? indicator.width : 10)
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;
}
}
}
}
}