Get elevation at a point

View on GitHubSample viewer app

Get the elevation for a given point on a surface in a scene.

Elevation at point

Use case

Knowing the elevation at a given point in a landscape can aid in navigation, planning and survey in the field.

How to use the sample

Tap anywhere on the surface to get the elevation at that point. Elevation is reported in the standard local measurements since the scene view is in WGS84.

How it works

  1. Create an AGSSceneView and an AGSScene with an imagery() basemap.
  2. Set the elevation source of the scene's base surface.
  3. Convert the tapped screen point into a point on surface.
  4. Asynchronously get the elevation using the AGSSurface.elevation(for:completion:) method and display the results.

Relevant API

  • AGSArcGISTiledElevationSource
  • AGSElevationSource
  • AGSSceneView
  • AGSSurface

Tags

elevation, point, surface

Sample Code

ElevationViewController.swiftElevationViewController.swiftGetElevationPointViewController.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
// Copyright 2019 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

class ElevationViewController: UIViewController {
    var elevation = Measurement(value: 0, unit: UnitLength.meters) {
        didSet {
            loadViewIfNeeded()
            elevationLabel.text = elevationFormatter.string(from: elevation)
            preferredContentSize = view.systemLayoutSizeFitting(UIView.layoutFittingExpandedSize)
        }
    }

    @IBOutlet private var elevationLabel: UILabel!

    private let elevationFormatter = MeasurementFormatter()
}

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