Geodesic Ellipse

Download Samples Repository

Description

This sample demonstrates use of the GeometryEngine.GeodesicEllipse to calculate a geodesic ellipse. Also shows is how to calculate a geodesic sector using GeometryEngine.GeodesicSector to create a geodesic sector emanating from point. To use the sample, fill in the ellipse properties and click the 'Geodesic Ellipse' button, then click a center point on the map. The click point and a geodesic ellipse and sector centered at the point will be displayed.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.GeodesicEllipse"
             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:SimpleMarkerSymbol x:Key="PointSymbol" Color="Black" Style="Circle" Size="4" />
            
            <esri:SimpleFillSymbol x:Key="EllipseSymbol" Color="#660000FF" Style="Solid">
                <esri:SimpleFillSymbol.Outline>
                    <esri:SimpleLineSymbol Color="Blue" Width="2" />
                </esri:SimpleFillSymbol.Outline>
            </esri:SimpleFillSymbol>

            <esri:SimpleFillSymbol x:Key="SectorSymbol" Color="#66FF0000" Style="Solid">
                <esri:SimpleFillSymbol.Outline>
                    <esri:SimpleLineSymbol Color="Red" Width="1" />
                </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="graphicsOverlay">
					<esri:GraphicsOverlay.Renderer>
						<esri:SimpleRenderer Symbol="{StaticResource EllipseSymbol}" />
					</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="Click the 'Geodesic Ellipse' button and click a point on the map to calculate a geodesic ellipse (and optionally a geodesic sector) centered around the point. "
                           Width="300" TextAlignment="Left" TextWrapping="Wrap" />

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

                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Primary Radius (miles):" Margin="8" 
                               TextAlignment="Right" VerticalAlignment="Center" />
                    <ComboBox x:Name="comboRadius1" Grid.Row="0" Grid.Column="1" SelectedIndex="0" Width="65" 
                              VerticalAlignment="Center" HorizontalContentAlignment="Center">
                        <sys:Double>250</sys:Double>
                        <sys:Double>500</sys:Double>
                        <sys:Double>750</sys:Double>
                        <sys:Double>1000</sys:Double>
                    </ComboBox>

                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Secondary Radius (miles):" Margin="8"
                               TextAlignment="Right" VerticalAlignment="Center" />
                    <ComboBox x:Name="comboRadius2" Grid.Row="1" Grid.Column="1" SelectedIndex="2" Width="65" 
                              VerticalAlignment="Center" HorizontalContentAlignment="Center">
                        <sys:Double>250</sys:Double>
                        <sys:Double>500</sys:Double>
                        <sys:Double>750</sys:Double>
                        <sys:Double>1000</sys:Double>
                    </ComboBox>

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

                    <TextBlock Grid.Row="3" Grid.Column="0" Text="Segment Length (miles):" Margin="8"
                               TextAlignment="Right" VerticalAlignment="Center" />
                    <ComboBox x:Name="comboSegmentLength" Grid.Row="3" Grid.Column="1" SelectedIndex="2" Width="65" 
                              VerticalAlignment="Center" HorizontalContentAlignment="Center">
                        <sys:Double>10</sys:Double>
                        <sys:Double>50</sys:Double>
                        <sys:Double>250</sys:Double>
                        <sys:Double>500</sys:Double>
                        <sys:Double>1000</sys:Double>
                    </ComboBox>

                    <CheckBox x:Name="chkSector"  Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" 
                              Content="Show Geodesic Sector" IsChecked="False" Margin="18,12,12,0"/>
                    <Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Margin="16,4,8,0" Padding="4"
                            BorderBrush="Gray" BorderThickness="1"
                            Visibility="{Binding ElementName=chkSector, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <StackPanel>
                            <Grid HorizontalAlignment="Center">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Row="0" Grid.Column="0" Text="Sector Angle:" Margin="8"
                                           TextAlignment="Right" VerticalAlignment="Center" />
                                <Slider x:Name="sliderSectorAxis" Grid.Row="0" Grid.Column="1" Margin="6"
                                    Orientation="Horizontal" Width="100" IsSnapToTickEnabled="True"
                                    TickPlacement="BottomRight" TickFrequency="45" AutoToolTipPlacement="BottomRight"
                                    Minimum="0" Maximum="360" Value="90" />

                                <TextBlock Grid.Row="1" Grid.Column="0" Text="Start Direction:" Margin="8"
                                           TextAlignment="Right" VerticalAlignment="Center" />
                                <Slider x:Name="sliderSectorStart" 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="45" />
                            </Grid>
                        </StackPanel>
                    </Border>
                </Grid>

                <Button Content="Geodesic Ellipse" Margin="8,8,8,0" HorizontalAlignment="Center"
                        Click="EllipseButton_Click" />
            </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="Click a point 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.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// This sample demonstrates use of the GeometryEngine.GeodesicEllipse to calculate a geodesic ellipse. Also shows is how to calculate a geodesic sector using GeometryEngine.GeodesicSector to create a geodesic sector emanating from point. To use the sample, fill in the ellipse properties and click the 'Geodesic Ellipse' button, then click a center point on the map. The click point and a geodesic ellipse and sector centered at the point will be displayed.
	/// </summary>
	/// <title>Geodesic Ellipse</title>
	/// <category>Geometry</category>
	public partial class GeodesicEllipse : UserControl
	{
		private Symbol _pinSymbol;
		private Symbol _sectorSymbol;
		private GraphicsOverlay _graphicsOverlay;

		/// <summary>Construct Geodesic Ellipse sample control</summary>
		public GeodesicEllipse()
		{
			InitializeComponent();

			_pinSymbol = layoutGrid.Resources["PointSymbol"] as Symbol;
			_sectorSymbol = layoutGrid.Resources["SectorSymbol"] as Symbol;
			_graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
		}

		private async void EllipseButton_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				while (MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry.Extent != null)
				{
					// Accept user point
					MapPoint userpoint = await MyMapView.Editor.RequestPointAsync() as MapPoint;

					MapPoint point = GeometryEngine.NormalizeCentralMeridian(userpoint) as MapPoint;

					// create the geodesic ellipse
					var radius1 = (double)comboRadius1.SelectedItem;
					var radius2 = (double)comboRadius2.SelectedItem;
					var axis = sliderAxis.Value;
					var maxLength = (double)comboSegmentLength.SelectedItem;
					var param = new GeodesicEllipseParameters(point, radius1, radius2, LinearUnits.Miles)
					{ 
						AxisDirection = axis, 
						MaxPointCount = 10000, 
						MaxSegmentLength = maxLength
					};
					var ellipse = GeometryEngine.GeodesicEllipse(param);

					//show geometries on map
					_graphicsOverlay.Graphics.Clear();
					_graphicsOverlay.Graphics.Add(new Graphic(point, _pinSymbol));
					_graphicsOverlay.Graphics.Add(new Graphic(ellipse));

					// geodesic sector
					if ((bool)chkSector.IsChecked)
					{
						var sectorParams = new GeodesicSectorParameters(point, radius1, radius2, LinearUnits.Miles)
						{
							AxisDirection = axis,
							MaxPointCount = 10000,
							MaxSegmentLength = maxLength,
							SectorAngle = sliderSectorAxis.Value,
							StartDirection = sliderSectorStart.Value
						};
						var sector = GeometryEngine.GeodesicSector(sectorParams);

						_graphicsOverlay.Graphics.Add(new Graphic(sector, _sectorSymbol));
					}
				}
			}
			catch (TaskCanceledException) { }
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "Error");
			}
		}
	}
}
Feedback on this topic?