Click or drag to resize

LocationDistanceMeasurement Class

An analysis object that evaluates direct, vertical, and horizontal distances between two points defined by start and end point locations.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.UI.GeoAnalysisAnalysis
    Esri.ArcGISRuntime.UI.GeoAnalysisLocationDistanceMeasurement

Namespace:  Esri.ArcGISRuntime.UI.GeoAnalysis
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public sealed class LocationDistanceMeasurement : Analysis

The LocationDistanceMeasurement type exposes the following members.

Constructors
  NameDescription
Public methodLocationDistanceMeasurement
Initializes a new instance of the LocationDistanceMeasurement class that defines a start and an end location using Point objects.
Public methodCode exampleLocationDistanceMeasurement(MapPoint, MapPoint)
Initializes a new instance of the LocationDistanceMeasurement class that defines a start and an end location using Point objects.
Top
Properties
  NameDescription
Public propertyCode exampleDirectDistance
Gets the direct distance component of the LocationDistanceMeasurement.
Public propertyCode exampleEndLocation
Gets or sets the end location of the LocationDistanceMeasurement.
Public propertyCode exampleHorizontalDistance
Gets the horizontal distance component of the LocationDistanceMeasurement.
Public propertyCode exampleIsVisible
Gets or sets a value indicating whether or not an Analysis is visible.
(Inherited from Analysis.)
Public propertyStartLocation
Gets or sets the start location of the LocationDistanceMeasurement.
Public propertyCode exampleUnitSystem
Gets or sets the start location of the LocationDistanceMeasurement.
Public propertyCode exampleVerticalDistance
Gets the vertical distance component of the LocationDistanceMeasurement.
Top
Events
  NameDescription
Public eventCode exampleMeasurementChanged
Raised when the measurement has changed.
Top
Remarks
LocationDistanceMeasurement measures the distance between a start and an end location (each using MapPoint geometry). Three distance components are calculated:
  • Direct distance - the direct distance between the start and end location
  • Horizontal distance - the horizontal component of the direct distance
  • Vertical distance - the vertical component of the direct distance
Examples

Android

Example Name: DistanceMeasurement

Measure distances between two points in 3D.

Code example screen shot.

C#
// 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: 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.

using Android.App;
using Android.OS;
using Android.Widget;
using Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using Esri.ArcGISRuntime.UI.GeoAnalysis;
using System;
using Debug = System.Diagnostics.Debug;

namespace ArcGISRuntime.Samples.DistanceMeasurement
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Distance measurement analysis",
        "Analysis",
        "This sample demonstrates measuring 3D distances between two points in a scene. The distance measurement analysis allows you to add the same measuring experience found in ArcGIS Pro, City Engine, and the ArcGIS API for JavaScript to your app. You can set the unit system of measurement (metric or imperial) and have the units automatically switch to one appropriate for the current scale. The rendering is handled internally so they do not interfere with other analyses like viewsheds.",
        "Tap to set a new end point for the measurement.",
        "Featured")]
    [ArcGISRuntime.Samples.Shared.Attributes.AndroidLayout("DistanceMeasurement.axml")]
    public class DistanceMeasurement : Activity
    {
        // Reference to UI controls.
        private TextView _directLabel;
        private TextView _verticalLabel;
        private TextView _horizontalLabel;
        private SceneView _mySceneView;
        private Spinner _unitSpinner;

        // URLs to various services used to provide an interesting scene for the sample.
        private readonly Uri _buildingService =
            new Uri(
                "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0");

        private readonly Uri _worldElevationService =
            new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");

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

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Distance measurement analysis";

            // Create the UI, setup the control references and execute initialization
            CreateLayout();
            Initialize();
        }

        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);
            myScene.OperationalLayers.Add(buildingsLayer);

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

            // 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);
            measureAnalysisOverlay.Analyses.Add(_distanceMeasurement);

            // 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.
                RunOnUiThread(() =>
                {
                    // Update the label with new values in the format {value} {unit system}.
                    _directLabel.Text =
                        $"{_distanceMeasurement.DirectDistance.Value:F} {_distanceMeasurement.DirectDistance.Unit.Abbreviation}";
                    _verticalLabel.Text =
                        $"{_distanceMeasurement.VerticalDistance.Value:F} {_distanceMeasurement.VerticalDistance.Unit.Abbreviation}";
                    _horizontalLabel.Text =
                        $"{_distanceMeasurement.HorizontalDistance.Value:F} {_distanceMeasurement.HorizontalDistance.Unit.Abbreviation}";
                });
            };

            // Update the unit spinner with the options.
            _unitSpinner.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerItem,
                Enum.GetNames(typeof(UnitSystem)));
            _unitSpinner.ItemSelected += (sender, args) =>
            {
                UnitSystem[] values = (UnitSystem[]) Enum.GetValues(typeof(UnitSystem));
                _distanceMeasurement.UnitSystem = values[args.Position];
            };

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

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

        private async void MySceneView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // 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)
            {
                Debug.WriteLine(ex.ToString());
            }
        }

        private void CreateLayout()
        {
            // Load the layout for the sample from the .axml file.
            SetContentView(Resource.Layout.DistanceMeasurement);

            // Update control references to point to the controls defined in the layout
            _mySceneView = FindViewById<SceneView>(Resource.Id.distanceMeasurement_sceneView);
            _directLabel = FindViewById<TextView>(Resource.Id.distanceMeasurement_directLabel);
            _verticalLabel = FindViewById<TextView>(Resource.Id.distanceMeasurement_verticalLabel);
            _horizontalLabel = FindViewById<TextView>(Resource.Id.distanceMeasurement_horizontalLabel);
            _unitSpinner = FindViewById<Spinner>(Resource.Id.distanceMeasurement_unitSpinner);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: DistanceMeasurement

Measure distances between two points in 3D.

Code example screen shot.

C#
// 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: 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.

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
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Distance measurement analysis",
        "Analysis",
        "This sample demonstrates measuring 3D distances between two points in a scene. The distance measurement analysis allows you to add the same measuring experience found in ArcGIS Pro, City Engine, and the ArcGIS API for JavaScript to your app. You can set the unit system of measurement (metric or imperial) and have the units automatically switch to one appropriate for the current scale. The rendering is handled internally so they do not interfere with other analyses like viewsheds.",
        "Tap to set a new end point for the measurement.",
        "Featured")]
    public partial class DistanceMeasurement : ContentPage
    {
        // URLs to various services used to provide an interesting scene for the sample.
        private readonly Uri _buildingService =
            new Uri(
                "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0");

        private readonly Uri _worldElevationService =
            new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");

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

        public DistanceMeasurement()
        {
            InitializeComponent();

            // Create the UI, setup the control references and execute initialization.
            Initialize();
        }

        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);
            myScene.OperationalLayers.Add(buildingsLayer);

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

            // 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);
            measureAnalysisOverlay.Analyses.Add(_distanceMeasurement);

            // 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)
        {
            try
            {
                // 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)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
    }
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             x:Class="ArcGISRuntime.Samples.DistanceMeasurement.DistanceMeasurement">
  <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <!-- Labels -->
        <Label x:Name="HelpLabel"
                       TextColor="Red"
                       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"
                          Margin="0,5,0,5"
                          />
        <esriUI:SceneView x:Name="MySceneView" 
                          Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" />
  </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
DistanceMeasurementMeasure distances between two points in 3D.