Blend a hillshade with a raster by specifying the elevation data. The resulting raster looks similar to the original raster, but with some terrain shading, giving it a textured look.
Use case
BlendRenderer can be used to apply a color ramp to a hillshade to emphasize areas of high or low elevation. A BlendRenderer can also be used to add a hillshade effect to aerial or satellite imagery, thereby making changes in elevation more visible.
How to use the sample
Choose and adjust the altitude, azimuth, slope type and color ramp type settings to update the image.
How it works
- Create a
Rasterobject from a raster file. - Create a
RasterLayerobject from the raster. - Create a
Basemapobject from the raster layer and set it to the map. - Create another
Rasterobject for elevation from a grayscale raster file. - Create a
BlendRendererobject, specifying the elevation raster, color ramp, and other properties.
- If you specify a non-
nilcolor ramp, use the elevation raster as the base raster in addition to the elevation raster parameter. That way, the color ramp is used instead of the satellite imagery.
- Set the blend renderer to the raster layer.
Relevant API
- BlendRenderer
- ColorRamp
- Raster
- RasterLayer
Offline data
This sample uses the Shasta Raster and Shasta Elevation Raster. Both are downloaded from ArcGIS Online automatically.
Tags
color ramp, elevation, hillshade, image, raster, raster layer, visualization
Sample Code
// Copyright 2025 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
//
// https://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.
import ArcGIS
import SwiftUI
struct ApplyBlendRendererToHillshadeView: View {
/// A map with no specified style.
@State private var map = Map()
/// The imagery basemap.
private let imageryBasemap: Basemap = {
let raster = Raster(fileURL: .shasta)
let rasterLayer = RasterLayer(raster: raster)
return Basemap(baseLayer: rasterLayer)
}()
/// The elevation basemap.
private let elevationBasemap: Basemap = {
let raster = Raster(fileURL: .shastaElevation)
let rasterLayer = RasterLayer(raster: raster)
return Basemap(baseLayer: rasterLayer)
}()
/// The imagery basemap raster layer.
private var imageryBasemapLayer: RasterLayer {
imageryBasemap.baseLayers[0] as! RasterLayer
}
/// The elevation basemap raster layer.
private var elevationBasemapLayer: RasterLayer {
elevationBasemap.baseLayers[0] as! RasterLayer
}
/// The elevation raster.
private let elevationRaster = Raster(fileURL: .shastaElevation)
/// A Boolean value indicating whether the settings view should be presented.
@State private var isShowingSettings = false
/// The settings for a blend renderer.
struct RendererSettings: Equatable {
/// The renderer altitude.
var altitude = 0.0
/// The renderer azimuth.
var azimuth = 0.0
/// The renderer slope type.
var slopeType: HillshadeRenderer.SlopeType?
/// The renderer color ramp preset.
var colorRampPreset: ColorRamp.Preset?
/// The renderer color ramp.
var colorRamp: ColorRamp? {
colorRampPreset.map { ColorRamp(preset: $0, size: 800) }
}
/// A Boolean value indicating whether the renderer has a color ramp.
var hasColorRamp: Bool {
colorRamp != nil
}
}
/// The renderer settings.
@State private var rendererSettings = RendererSettings()
var body: some View {
MapView(map: map)
.onChange(of: rendererSettings, initial: true) {
let rasterLayer = rendererSettings.hasColorRamp ? elevationBasemapLayer : imageryBasemapLayer
rasterLayer.renderer = BlendRenderer(
elevationRaster: elevationRaster,
outputMinValues: [9],
outputMaxValues: [255],
sourceMinValues: [],
sourceMaxValues: [],
noDataValues: [],
gammas: [],
colorRamp: rendererSettings.colorRamp,
altitude: rendererSettings.altitude,
azimuth: rendererSettings.azimuth,
slopeType: rendererSettings.slopeType
)
map.basemap = rendererSettings.hasColorRamp ? elevationBasemap : imageryBasemap
}
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button("Renderer Settings") {
isShowingSettings = true
}
.popover(isPresented: $isShowingSettings) {
SettingsView(settings: $rendererSettings)
.presentationDetents([.fraction(0.5)])
.frame(idealWidth: 320, idealHeight: 320)
}
}
}
}
}
private extension URL {
/// The URL to the Shasta data.
static var shasta: URL {
Bundle.main.url(forResource: "Shasta", withExtension: "tif", subdirectory: "raster-file/raster-file")!
}
/// The URL to the Shasta elevation data.
static var shastaElevation: URL {
Bundle.main.url(forResource: "Shasta_Elevation", withExtension: "tif", subdirectory: "Shasta_Elevation")!
}
}