Click or drag to resize

Distance Class

Distance holds the distance measurement data associated with a specific distance component.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Geometry
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.9.0
public sealed class Distance

The Distance type exposes the following members.

Public propertyCode exampleUnit
Gets the unit of the Distance component.
Public propertyCode exampleValue
Gets the value of the Distance component.


Example Name: DistanceMeasurement

Measure distances between two points in 3D.

Code example screen shot.

// 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.Controls;
using Esri.ArcGISRuntime.UI.GeoAnalysis;
using System;
using System.Windows;
using System.Windows.Input;

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

        private readonly Uri _buildingService =
            new Uri(

        // Measurement.
        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.
                Dispatcher.Invoke(() =>
                    // Update the labels with new values in the format {value} {unit system}.
                    DirectMeasureLabel.Content = string.Format("{0:F} {1}", _distanceMeasurement.DirectDistance.Value,
                    VerticalMeasureLabel.Content = string.Format("{0:F} {1}", _distanceMeasurement.VerticalDistance.Value,
                    HorizontalMeasureLabel.Content = string.Format("{0:F} {1}",

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

            // Update the unit system selection.
            UnitSystemCombo.SelectionChanged += (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));

            // Enable the 'New measurement' button.
            NewMeasureButton.IsEnabled = true;

        private void MySceneView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
            // Unsubscribe from events to finish the measurement.
            MySceneView.MouseMove -= MySceneView_MouseMoved;
            MySceneView.GeoViewTapped -= MySceneView_GeoViewTapped;

            // Re-enable the new measurement button.
            NewMeasureButton.IsEnabled = true;

            // Re-set the help label.
            HelpLabel.Content = "Tap 'New measurement' to start.";

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

                if (geoPoint == null)

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

        private void NewMeasureButton_OnClick(object sender, RoutedEventArgs e)
            // Subscribe to mouse move to change the measurement.
            MySceneView.MouseMove += MySceneView_MouseMoved;

            // Subscribe to the tap method to enable finishing a measurement.
            MySceneView.GeoViewTapped += MySceneView_GeoViewTapped;

            // Disable the button.
            NewMeasureButton.IsEnabled = false;

            // Update the help label.
            HelpLabel.Content = "Move the mouse to update the end point. Tap again to finish.";
<UserControl x:Class="ArcGISRuntime.WPF.Samples.DistanceMeasurement.DistanceMeasurement"
             d:DesignHeight="300" d:DesignWidth="600">
        <esri:SceneView x:Name="MySceneView" />
        <Border Style="{StaticResource BorderStyle}">
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                <!-- Labels -->
                <Label x:Name="HelpLabel"
                       Content="Tap 'New measurement' to start."
                       HorizontalAlignment="Center" FontWeight="SemiBold"
                       Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
                <Label Content="Direct" 
                       Grid.Row="1" Grid.Column="0" />
                <Label Content="Horizontal"
                       Grid.Row="2" Grid.Column="0" />
                <Label Content="Vertical"
                       Grid.Row="3" Grid.Column="0" />
                <Label Content="Unit system"
                       Grid.Row="4" 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" />
                <ComboBox x:Name="UnitSystemCombo"
                          Grid.Row="4" Grid.Column="1"
                          Margin="0,5,0,0" />

                <Button x:Name="NewMeasureButton"
                        Content="New measurement"
                        Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2"
                        Click="NewMeasureButton_OnClick" />
See Also
Additional Examples
Hyperlink to ExampleDescription
DistanceMeasurementMeasure distances between two points in 3D.