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
Create a SceneView and Scene with an imagery base map.
Set an ArcGISTiledElevationSource as the elevation source of the scene's base surface.
Use the screenToBaseSurface(screenPoint) method on the scene view to convert the clicked screen point into a point on surface.
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
GetElevationAtPoint.qml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// [WriteFile Name=GetElevationAtPoint, Category=Scenes]// [Legal]// 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.// [Legal]import Esri.ArcGISRuntime
import QtQuick
import QtQuick.Controls
Rectangle {
id: rootRectangleclip: truewidth: 800height: 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 : nullSceneView {
id: sceneViewanchors.fill: parentScene {
id: sceneBasemap {
initStyle: Enums.BasemapStyleArcGISImageryStandard
}
Surface {
id: elevationSurfaceArcGISTiledElevationSource {
url: "https://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: graphicsOverlayGraphic {
id: elevationMarkersymbol: elevationMarkerSymbol
}
}
// A simple red dot, displays the point elevation is queried at.SimpleMarkerSymbol {
id: elevationMarkerSymbolstyle: 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: mouse => {
lastQueriedSurfacePos = sceneView.screenToBaseSurface(mouse.x, mouse.y)
elevationSurface.locationToElevation(lastQueriedSurfacePos)
}
Component.onCompleted: {
// Set the focus on SceneView to initially enable keyboard navigation forceActiveFocus();
// Once the scene view has loaded, apply the camera. setViewpointCameraAndWait(camera);
}
}
// Create the camera to be used as the scene view's viewpoint, looking at the Himalayan mountain range.Camera {
id: cameralocation: Point {
x: 83.9// Longitudey: 28.4// Latitudez: 10010.0// AltiudespatialReference: SpatialReference { wkid: 4326 }
}
heading: 10.0pitch: 83.9roll: 0.0 }
// Background rectangle for elevation displayRectangle {
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 textText {
id: elevationDisplaytextanchors {
horizontalCenter: parent.horizontalCenter
}
color: "white"padding: 15font.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 secondsBusyIndicator {
running: elevationSurface.locationToElevationStatus === Enums.TaskStatusInProgress
anchors.centerIn: parentwidth: Math.min(parent.width, parent.height) / 6.0height: width
}
}