Get elevation at point on surface

View on GitHubSample viewer app

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

Image of get 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 meters since the scene view is in WGS84.

How it works

  1. Create a composable SceneView and ArcGISScene with an imagery base map.
  2. Set an ArcGISTiledElevationSource as the elevation source of the scene's baseSurface.
  3. Use the screenToLocation(screenCoordinate) function on the scene view to convert the tapped screen coordinate into a point on surface.
  4. Use the getElevation(scenePoint) method on the base surface to asynchronously get the elevation.

Relevant API

  • ArcGISTiledElevationSource
  • BaseSurface
  • ElevationSource
  • SceneView

Additional information

getElevation(scenePoint) retrieves the most accurate available elevation value at a given point. To do this, the method must 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

GetElevationAtPointOnSurfaceViewModel.ktGetElevationAtPointOnSurfaceViewModel.ktMainActivity.ktGetElevationAtPointOnSurfaceScreen.kt
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
/* 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
 *
 *    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.
 *
 */

package com.esri.arcgismaps.sample.getelevationatpointonsurface.components

import android.app.Application
import android.widget.Toast
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.arcgismaps.mapping.ArcGISScene
import com.arcgismaps.mapping.ArcGISTiledElevationSource
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
import com.arcgismaps.mapping.view.Camera
import com.arcgismaps.mapping.view.Graphic
import com.arcgismaps.mapping.view.GraphicsOverlay
import com.arcgismaps.mapping.view.SingleTapConfirmedEvent
import com.arcgismaps.toolkit.geoviewcompose.SceneViewProxy
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel
import kotlinx.coroutines.launch
import kotlin.math.roundToInt


class GetElevationAtPointOnSurfaceViewModel(application: Application) : AndroidViewModel(application) {

    val sceneViewProxy = SceneViewProxy()

    val arcGISScene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
        // Add an elevation source to the scene's base surface.
        baseSurface.elevationSources.add(
            ArcGISTiledElevationSource(
                "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"
            )
        )
    }

    // Graphics overlay used to add feature graphics to the map
    val graphicsOverlay = GraphicsOverlay()

    // Create a message dialog view model for handling error messages
    val messageDialogVM = MessageDialogViewModel()

    init {
        viewModelScope.launch {
            arcGISScene.load().onSuccess {
                // Set the initial viewpoint of the scene view, once loaded
                sceneViewProxy.setViewpointCamera(
                    Camera(
                        latitude = 28.42, longitude = 83.9, altitude = 10000.0, heading = 10.0, pitch = 80.0, roll = 0.0
                    )
                )
            }.onFailure { error ->
                messageDialogVM.showMessageDialog(
                    "Failed to load map", error.message.toString()
                )
            }
        }
    }

    /**
     * Get the elevation at the point on the surface where the user taps.
     */
    fun getElevation(singleTapConfirmedEvent: SingleTapConfirmedEvent) {
        viewModelScope.launch {
            sceneViewProxy.screenToLocation(singleTapConfirmedEvent.screenCoordinate).onSuccess { scenePoint ->
                arcGISScene.baseSurface.getElevation(scenePoint).onSuccess { elevation ->
                    // Create a point symbol to mark where elevation is being measured
                    val circleSymbol = SimpleMarkerSymbol(
                        style = SimpleMarkerSymbolStyle.Circle, color = com.arcgismaps.Color.red, size = 10f
                    )
                    // Add the graphic to the graphics overlay
                    graphicsOverlay.graphics.add(Graphic(geometry = scenePoint, symbol = circleSymbol))
                    // Show a toast message with the elevation
                    Toast.makeText(
                        getApplication(), "Elevation at point is ${elevation.roundToInt()} meters", Toast.LENGTH_LONG
                    ).show()
                }.onFailure { error ->
                    messageDialogVM.showMessageDialog(
                        "Failed to get elevation", error.message.toString()
                    )
                }
            }
        }
    }
}

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