Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Get elevation at point

Sample Viewer View Sample on GitHub

Get the elevation for a given point on a surface.

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

Click anywhere on the surface to get the elevation at that point.

How it works

  1. Create a SceneView and Scene with an imagery base map.
  2. Set an ArcGISTiledElevationSource as the elevation source of the scene's base surface.
  3. Use the screenToBaseSurface(screenPoint) method on the scene view to convert the clicked screen point into a point on surface.
  4. Use the locationToElevation(surfacePoint) method on the base surface to asynchronously get the elevation.

Relevant API

  • ArcGISTiledElevationSource
  • BaseSurface
  • ElevationSourceListModel
  • SceneView

Additional information

Calling locationToElevation(surfacePoint) retrieves the most accurate available elevation value at a given point which requires it to go to the server or local raster file and load the highest level of detail of data for the target location and return the elevation value.

If multiple elevation sources are present in the surface the top most visible elevation source with a valid elevation in the given location is used to determine the result.

Tags

elevation, surface

Sample Code

import Esri.ArcGISRuntime 100.9
import QtQuick 2.6
import QtQuick.Controls 2.2

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    // The position on the surface that was last queried for altitude, so the marker can be set in the onLocationToElevationResultChanged callback.
    property Point lastQueriedSurfacePos : null

    SceneView {
        id: sceneView
        anchors.fill: parent

        Scene {
            id: scene
            BasemapImagery {}

            Surface {
                id: elevationSurface
                ArcGISTiledElevationSource {
                    url: "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"
                }

                // When location has changed, set the elevation text to display new elevation, and move the elevationMarker to the queried-for position on the surface.
                onLocationToElevationResultChanged:
                    if(locationToElevationStatus === Enums.TaskStatusCompleted) {
                        // Display elevation value in meters, round to a single decimal place.
                        elevationDisplaytext.text = "Elevation : " + Math.round(locationToElevationResult * 10) / 10 + "m"
                        elevationMarker.geometry = lastQueriedSurfacePos;
                    }
            }
        }

        // A graphics overlay to display the elevaton marker.
        GraphicsOverlay {
            id: graphicsOverlay
            Graphic {
                id: elevationMarker
                symbol: elevationMarkerSymbol
            }
        }

        // A simple red dot, displays the point elevation is queried at.
        SimpleMarkerSymbol {
            id: elevationMarkerSymbol
            style: Enums.SimpleMarkerSymbolStyleCircle
            color: "red"
            size: 10
        }

        // When the mouse is clicked, convert mouse screen-position to position on surface, then invoke a query for the elevation of that position.
        onMouseClicked: {
            lastQueriedSurfacePos = sceneView.screenToBaseSurface(mouse.x, mouse.y)
            elevationSurface.locationToElevation(lastQueriedSurfacePos)
        }

        // Once the scene view has loaded, apply the camera.
        Component.onCompleted: {
            setViewpointCameraAndWait(camera);
        }
    }

    // Create the camera to be used as the scene view's viewpoint, looking at the Himalayan mountain range.
    Camera {
        id: camera
        location: Point {
            x: 83.9 // Longitude
            y: 28.4 // Latitude
            z: 10010.0 // Altiude
            spatialReference: SpatialReference { wkid: 4326 }
        }
        heading: 10.0
        pitch: 83.9
        roll: 0.0
    }

    // Background rectangle for elevation display
    Rectangle {
        anchors {
            bottom: parent.bottom
            left: parent.left
            right: parent.right
            margins: 30
        }

        color: Qt.rgba(0.2, 0.2, 0.2, 0.65);
        height: childrenRect.height

        // Elevation display text
        Text {
            id: elevationDisplaytext
            anchors {
                horizontalCenter: parent.horizontalCenter
            }
            color: "white"
            padding: 15
            font.pointSize: 32

            // For vertical screens, keep the text within the bounding box via scaling down.
            scale: Math.min(1, (parent.width - padding) / contentWidth)

            // Display elevation value in meters, round to a single decimal place.
            text: "Elevation : 0"
        }
    }

    // Display an indictor when the elevation query is running, since it might take a couple of seconds
    BusyIndicator {
        running: elevationSurface.locationToElevationStatus === Enums.TaskStatusInProgress
        anchors.centerIn: parent
        width: Math.min(parent.width, parent.height) / 6.0
        height: width
    }
}