Hillshade renderer

View inQMLC++
View on GitHub
Sample viewer app

Apply a hillshade renderer to a raster.

screenshot

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

Hillshade_Renderer.qmlHillshadeSettings.qmlHillshadeSlopeTypeModel.qml
                                                                                                  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// [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 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.12
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;
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.