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
.
- Create a
Raster
from a grayscale raster file. - Create a
RasterLayer
from the raster. - Create a
Basemap
from the raster layer and set it to the map. - Create a
HillshadeRenderer
, specifying the slope type and other properties. - 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
// [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.15
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
Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();
}
//! [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;
}
}