Hillshade renderer

View on GitHubSample viewer app

Apply a hillshade renderer to a raster.

Hillshade renderer initial view Hillshade renderer settings

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 an AGSRaster from a grayscale raster file.
  2. Create an AGSRasterLayer from the raster.
  3. Create an AGSBasemap from the raster layer and set it to the map.
  4. Create an AGSHillshadeRenderer, specifying the altitude and other properties.
  5. Set raster layer's AGSRenderer to the previously created AGSHillshadeRenderer.

Relevant API

  • AGSBasemap
  • AGSHillshadeRenderer
  • AGSRaster
  • AGSRasterLayer

Tags

altitude, angle, azimuth, raster, slope, visualization

Sample Code

HillshadeRendererViewController.swiftHillshadeRendererViewController.swiftHillshadeSettingsViewController.swift
Use dark colors for code blocksCopy
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
// 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.

import UIKit
import ArcGIS

class HillshadeRendererViewController: UIViewController {
    @IBOutlet var mapView: AGSMapView!

    private weak var rasterLayer: AGSRasterLayer?

    override func viewDidLoad() {
        super.viewDidLoad()

        // add the source code button item to the right of navigation bar
        (navigationItem.rightBarButtonItem as! SourceCodeBarButtonItem).filenames = [
            "HillshadeRendererViewController",
            "HillshadeSettingsViewController",
            "OptionsTableViewController"
        ]

        let raster = AGSRaster(name: "srtm", extension: "tiff")
        let rasterLayer = AGSRasterLayer(raster: raster)
        self.rasterLayer = rasterLayer

        let map = AGSMap(basemap: AGSBasemap(baseLayer: rasterLayer))

        mapView.map = map

        // initial renderer
        setRenderer(altitude: 45, azimuth: 315, slopeType: .none)
    }

    private func setRenderer(altitude: Double, azimuth: Double, slopeType: AGSSlopeType) {
        let renderer = AGSHillshadeRenderer(altitude: altitude, azimuth: azimuth, zFactor: 0.000016, slopeType: slopeType, pixelSizeFactor: 1, pixelSizePower: 1, outputBitDepth: 8)
        rasterLayer?.renderer = renderer
    }

    // MARK: - Navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let navController = segue.destination as? UINavigationController,
            let controller = navController.viewControllers.first as? HillshadeSettingsViewController,
            let renderer = rasterLayer?.renderer as? AGSHillshadeRenderer {
            controller.preferredContentSize = CGSize(width: 375, height: 135)
            navController.presentationController?.delegate = self
            controller.delegate = self
            controller.altitude = renderer.altitude
            controller.azimuth = renderer.azimuth
            controller.slopeType = renderer.slopeType
        }
    }
}

extension HillshadeRendererViewController: HillshadeSettingsViewControllerDelegate {
    func hillshadeSettingsViewController(_ controller: HillshadeSettingsViewController, selectedAltitude altitude: Double, azimuth: Double, slopeType: AGSSlopeType) {
        setRenderer(altitude: altitude, azimuth: azimuth, slopeType: slopeType)
    }
}

extension HillshadeRendererViewController: UIAdaptivePresentationControllerDelegate {
    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
    }
}

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