Geodesic Buffer

Download Samples Repository

Description

This sample demonstrates use of the GeometryEngine to calculate a geodesic buffer. To use the sample, click a point on the map. The click point and a geodesic buffer of 500 miles around the point will be shown.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.GeodesicBuffer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid x:Name="layoutGrid">
        <Grid.Resources>
            <esri:SimpleFillSymbol x:Key="BufferSymbol" Color="#660000FF" Style="Solid">
                <esri:SimpleFillSymbol.Outline>
                    <esri:SimpleLineSymbol Color="Blue" Width="2" />
                </esri:SimpleFillSymbol.Outline>
            </esri:SimpleFillSymbol>
        </Grid.Resources>

        <esri:MapView x:Name="MyMapView" WrapAround="True" MouseMove="MyMapView_MouseMove">
            <esri:Map>
				<esri:ArcGISTiledMapServiceLayer
                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
			</esri:Map>
			<esri:MapView.GraphicsOverlays>
				<esri:GraphicsOverlay ID="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>
            <TextBlock x:Name="InstructionsTextBlock" Text="Move the mouse to see a 500-mile geodesic buffer around the mouse location." 
                       Width="250" TextWrapping="Wrap" VerticalAlignment="Center" 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.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// This sample demonstrates use of the GeometryEngine to calculate a geodesic buffer. To use the sample, click a point on the map. The click point and a geodesic buffer of 500 miles around the point will be shown.
    /// </summary>
    /// <title>Geodesic Buffer</title>
    /// <category>Geometry</category>
    public partial class GeodesicBuffer : UserControl
    {
        private SimpleFillSymbol _bufferSymbol;
		private GraphicsOverlay _graphicsOverlay;

        /// <summary>Construct Geodesic Buffer sample control</summary>
        public GeodesicBuffer()
        {
            InitializeComponent();
			_graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
            _bufferSymbol = layoutGrid.Resources["BufferSymbol"] as SimpleFillSymbol;
        }

        private void MyMapView_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                // Convert screen point to map point
                var point = MyMapView.ScreenToLocation(e.GetPosition(MyMapView));
                if (point == null)
                    return;

                var buffer = GeometryEngine.GeodesicBuffer(
					GeometryEngine.NormalizeCentralMeridian(point), //Normalize in case we we're too far west/east of the world bounds
                    500, LinearUnits.Miles);

                Graphic bufferGraphic = null;
				if (_graphicsOverlay.Graphics.Count == 0)
                {
                    bufferGraphic = new Graphic { Geometry = buffer, Symbol = _bufferSymbol };
					_graphicsOverlay.Graphics.Add(bufferGraphic);
                }
                else
					bufferGraphic = _graphicsOverlay.Graphics[0];
                bufferGraphic.Geometry = buffer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Geometry Engine Failed!");
            }
        }
    }
}
Feedback on this topic?