Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Distance measurement analysis

This code sample is available for these platforms:
View Sample on GitHub

Measure distances between two points in 3D.

Image of distance measurement analysis

Use case

The distance measurement analysis allows you to add to your app the same interactive measuring experience found in ArcGIS Pro, City Engine, and the ArcGIS API for JavaScript. You can set the unit system of measurement (metric or imperial). The units automatically switch to one appropriate for the current scale.

How to use the sample

Choose a unit system for the measurement. Tap any location in the scene to start measuring. Move the mouse to an end location, and tap to complete the measurement. Tap a new location to clear and start a new measurement.

How it works

  1. Create an AnalysisOverlay object and add it to the analysis overlay collection of the SceneView object.
  2. Specify the start location and end location to create a LocationDistanceMeasurement object. Initially, the start and end locations can be the same point.
  3. Add the location distance measurement analysis to the analysis overlay.
  4. The MeasurementChanged event will be raised if the distances change. You can get the new values for the DirectDistance, HorizontalDistance, and VerticalDistance from the event arguments.

Relevant API

  • AnalysisOverlay
  • LocationDistanceMeasurement
  • LocationDistanceMeasurement.MeasurementChanged

Additional information

The LocationDistanceMeasurement analysis only performs planar distance calculations. This may not be appropriate for large distances where the Earth's curvature must be considered.


3D, analysis, distance, measure

Sample Code

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        <!-- Labels -->
        <Label x:Name="HelpLabel"
                       Text="Tap to update the measurement."
                       Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
        <Label Text="Direct" 
                       Grid.Row="1" Grid.Column="0" />
        <Label Text="Horizontal"
                       Grid.Row="2" Grid.Column="0" />
        <Label Text="Vertical"
                       Grid.Row="3" Grid.Column="0" />

        <!-- Controls -->
        <Label x:Name="DirectMeasureLabel"
                       Grid.Row="1" Grid.Column="1" />
        <Label x:Name="HorizontalMeasureLabel"
                       Grid.Row="2" Grid.Column="1" />
        <Label x:Name="VerticalMeasureLabel"
                       Grid.Row="3" Grid.Column="1" />
        <Picker x:Name="UnitSystemCombo"
                          Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
        <esriUI:SceneView x:Name="MySceneView" 
                          Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" />
// Copyright 2018 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:
// 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.

using Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.GeoAnalysis;
using Esri.ArcGISRuntime.Xamarin.Forms;
using System;
using System.Diagnostics;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.DistanceMeasurement
        name: "Distance measurement analysis",
        category: "Analysis",
        description: "Measure distances between two points in 3D.",
        instructions: "Choose a unit system for the measurement. Tap any location in the scene to start measuring. Move the mouse to an end location, and tap to complete the measurement. Tap a new location to clear and start a new measurement.",
        tags: new[] { "3D", "analysis", "distance", "measure" })]
    public partial class DistanceMeasurement : ContentPage
        // URLs to various services used to provide an interesting scene for the sample.
        private readonly Uri _buildingService =
            new Uri(

        private readonly Uri _worldElevationService =
            new Uri("");

        // Reference to the measurement used.
        private LocationDistanceMeasurement _distanceMeasurement;

        public DistanceMeasurement()
            // Create the UI, setup the control references and execute initialization.

        private void Initialize()
            // Create a scene with elevation.
            Surface sceneSurface = new Surface();
            sceneSurface.ElevationSources.Add(new ArcGISTiledElevationSource(_worldElevationService));
            Scene myScene = new Scene(Basemap.CreateImagery())
                BaseSurface = sceneSurface

            // Create and add a building layer.
            ArcGISSceneLayer buildingsLayer = new ArcGISSceneLayer(_buildingService);

            // Create and add an analysis overlay.
            AnalysisOverlay measureAnalysisOverlay = new AnalysisOverlay();

            // Create an initial distance measurement and show it.
            MapPoint start = new MapPoint(-4.494677, 48.384472, 24.772694, SpatialReferences.Wgs84);
            MapPoint end = new MapPoint(-4.495646, 48.384377, 58.501115, SpatialReferences.Wgs84);
            _distanceMeasurement = new LocationDistanceMeasurement(start, end);

            // Keep the UI updated.
            _distanceMeasurement.MeasurementChanged += (o, e) =>
                // This is needed because measurement change events occur on a non-UI thread and this code accesses UI object.
                Device.BeginInvokeOnMainThread(() =>
                    // Update the labels with new values in the format {value} {unit system}.
                    DirectMeasureLabel.Text =
                        $"{_distanceMeasurement.DirectDistance.Value:F} {_distanceMeasurement.DirectDistance.Unit.Abbreviation}";
                    VerticalMeasureLabel.Text =
                        $"{_distanceMeasurement.VerticalDistance.Value:F} {_distanceMeasurement.VerticalDistance.Unit.Abbreviation}";
                    HorizontalMeasureLabel.Text =
                        $"{_distanceMeasurement.HorizontalDistance.Value:F} {_distanceMeasurement.HorizontalDistance.Unit.Abbreviation}";

            // Configure the unit system selection box.
            UnitSystemCombo.ItemsSource = Enum.GetValues(typeof(UnitSystem));
            UnitSystemCombo.SelectedItem = _distanceMeasurement.UnitSystem;

            // Update the unit system selection.
            UnitSystemCombo.SelectedIndexChanged += (sender, args) =>
                _distanceMeasurement.UnitSystem = (UnitSystem) UnitSystemCombo.SelectedItem;

            // Show the scene in the view.
            MySceneView.Scene = myScene;
            MySceneView.SetViewpointCamera(new Camera(start, 200, 0, 45, 0));

            // Subscribe to tap events to enable updating the measurement.
            MySceneView.GeoViewTapped += MySceneView_GeoViewTapped;

        private async void MySceneView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
                // Get the geographic location for the current mouse position.
                MapPoint geoPoint = await MySceneView.ScreenToLocationAsync(e.Position);

                if (geoPoint == null) return;

                // Update the location distance measurement.
                _distanceMeasurement.EndLocation = geoPoint;
            catch (Exception ex)