Geodesic Move

Download Samples Repository

Description

This sample demonstrates use of the GeometryEngine.GeodesicMove method to move a geometry be a specified distance. To use the sample, first digitize a polygon on the map. Then set the move distance and angle properties and click the 'Geodesic Move' button. The original polygon and the new moved polygon will be displayed.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.GeodesicMove"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid x:Name="layoutGrid">
        <Grid.Resources>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

            <esri:SimpleFillSymbol x:Key="OriginalSymbol" Color="#660000FF" Style="Solid">
                <esri:SimpleFillSymbol.Outline>
                    <esri:SimpleLineSymbol Color="Blue" Width="2" />
                </esri:SimpleFillSymbol.Outline>
            </esri:SimpleFillSymbol>

            <esri:SimpleFillSymbol x:Key="MovedSymbol" Color="#66FF0000" Style="Solid">
                <esri:SimpleFillSymbol.Outline>
                    <esri:SimpleLineSymbol Color="Red" Width="2" />
                </esri:SimpleFillSymbol.Outline>
            </esri:SimpleFillSymbol>
        </Grid.Resources>

        <esri:MapView x:Name="MyMapView" WrapAround="True">
            <esri:Map>
				<esri:ArcGISTiledMapServiceLayer
                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer" />
			</esri:Map>
			<esri:MapView.GraphicsOverlays>
				<esri:GraphicsOverlay ID="originalOverlay">
					<esri:GraphicsOverlay.Renderer>
						<esri:SimpleRenderer Symbol="{StaticResource OriginalSymbol}" />
					</esri:GraphicsOverlay.Renderer>
				</esri:GraphicsOverlay>
				<esri:GraphicsOverlay ID="movedOverlay">
					<esri:GraphicsOverlay.Renderer>
						<esri:SimpleRenderer Symbol="{StaticResource MovedSymbol}" />
					</esri:GraphicsOverlay.Renderer>
				</esri:GraphicsOverlay>
			</esri:MapView.GraphicsOverlays>
        </esri:MapView>

		<Border Background="White" BorderBrush="Black" BorderThickness="1"
				 HorizontalAlignment="Right" VerticalAlignment="Top"
				 Margin="30" Padding="20">
			<Border.Effect>
				<DropShadowEffect/>
			</Border.Effect>
			<StackPanel>
                <TextBlock Text="Digitize a polygon on the map and then click the 'Geodesic Move' button to move the polygon the specified distance and angle. "
                           Width="275" TextWrapping="Wrap" />

                <Grid Margin="12,20,12,12" HorizontalAlignment="Center">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Move Distance (miles):" Margin="8" 
                               TextAlignment="Right" VerticalAlignment="Center" />
                    <ComboBox x:Name="comboDistance" Grid.Row="0" Grid.Column="1" SelectedIndex="1" Width="65" 
                              VerticalAlignment="Center" HorizontalContentAlignment="Center">
                        <sys:Double>500</sys:Double>
                        <sys:Double>1000</sys:Double>
                        <sys:Double>2000</sys:Double>
                    </ComboBox>

                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Azimuth (degrees):" Margin="8"
                               TextAlignment="Right" VerticalAlignment="Center" />
                    <Slider x:Name="sliderAngle" Grid.Row="1" Grid.Column="1" Margin="6"
                            Orientation="Horizontal" Width="100" IsSnapToTickEnabled="True"
                            TickPlacement="BottomRight" TickFrequency="45" AutoToolTipPlacement="BottomRight"
                            Minimum="0" Maximum="360" Value="180" />
                </Grid>

                <StackPanel Orientation="Horizontal" Margin="8,8,8,0" HorizontalAlignment="Center">
                    <Button Content="Digitize Polygon" Margin="8,8,8,0" Click="DigitizeButton_Click" />
                    <Button Content="Geodesic Move" Margin="8,8,8,0" Click="GeodesicMoveButton_Click" />
                </StackPanel>
            </StackPanel>
        </Border>

        <Border Background="White" BorderBrush="Black" BorderThickness="2" Margin="25"
                HorizontalAlignment="Center" VerticalAlignment="Bottom"
                Visibility="{Binding ElementName=MyMapView, Path=Editor.IsActive, Converter={StaticResource BooleanToVisibilityConverter}}">
            <TextBlock Text="Digitize a polygon on the map." Margin="8" FontSize="14" />
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Symbology;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// This sample demonstrates use of the GeometryEngine.GeodesicMove method to move a geometry be a specified distance. To use the sample, first digitize a polygon on the map. Then set the move distance and angle properties and click the 'Geodesic Move' button. The original polygon and the new moved polygon will be displayed.
    /// </summary>
    /// <title>Geodesic Move</title>
	/// <category>Geometry</category>
	public partial class GeodesicMove : UserControl
    {
        private Symbol _origSymbol;
		private GraphicsOverlay _originalOverlay;
		private GraphicsOverlay _movedOverlay;

        /// <summary>Construct Geodesic Move sample control</summary>
        public GeodesicMove()
        {
            InitializeComponent();

            _origSymbol = layoutGrid.Resources["OriginalSymbol"] as Symbol;
			_originalOverlay = MyMapView.GraphicsOverlays["originalOverlay"];
			_movedOverlay = MyMapView.GraphicsOverlays["movedOverlay"];

            MyMapView.ExtentChanged += MyMapView_ExtentChanged;
        }

        // Start map interaction once the mapview extent is set
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            MyMapView.ExtentChanged -= MyMapView_ExtentChanged;

            MyMapView.Editor.EditorConfiguration.MidVertexSymbol = null;
            MyMapView.Editor.EditorConfiguration.VertexSymbol = null;
            MyMapView.Editor.EditorConfiguration.SelectedVertexSymbol = new SimpleMarkerSymbol() 
			{ 
				Color = System.Windows.Media.Colors.Blue, 
				Size = 6 
			};

            await AcceptUserPolygonAsync();
        }

        // Digitize a new original polygon to move
        private async void DigitizeButton_Click(object sender, RoutedEventArgs e)
        {
            await AcceptUserPolygonAsync();
        }

        // Get the polygon from the user
        private async Task AcceptUserPolygonAsync()
        {
            try
            {
                _movedOverlay.Graphics.Clear();
				_originalOverlay.Graphics.Clear();

                var polygon = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon, _origSymbol);

				_originalOverlay.Graphics.Add(new Graphic(polygon));
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Geodesic Move Sample");
            }
        }

        // Move the polygon the specified distance and angle
        private void GeodesicMoveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_originalOverlay.Graphics.Count == 0)
                    throw new ApplicationException("Digitize a polygon to move.");

				var coords = _originalOverlay.Graphics[0].Geometry as Multipart;
                if (coords == null)
                    throw new ApplicationException("Digitize a polygon to move.");

                var points = coords.Parts.First().GetPoints();
                var distance = (double)comboDistance.SelectedItem;
                var azimuth = (double)sliderAngle.Value;
                var movedPoints = GeometryEngine.GeodesicMove(points, distance, LinearUnits.Miles, azimuth);

                Polygon movedPoly = new Polygon(movedPoints, MyMapView.SpatialReference);
				_movedOverlay.Graphics.Clear();
				_movedOverlay.Graphics.Add(new Graphic(movedPoly));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Geodesic Move Sample");
            }
        }
    }
}
Feedback on this topic?