Click or drag to resize
Code Example - GeometryEngine_Buffer

Demonstrates using the powerful GeometryEngine local process to generate graphic buffer polygons based upon a user specified radius and mouse-clicks/taps on the map.

Code Example
Geometry Engine Buffer

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

<Window x:Class="GeometryEngine_Buffer.MainWindow"
        Title="MainWindow" Height="600" Width="800">

    <Grid x:Name="layoutGrid">

        <!-- Define a SimpleMarkerSymbol and SimpleFillSymbol in the Grid Resources. -->

            <!-- A red point, size 10.-->
            <esri:SimpleMarkerSymbol x:Key="PointSymbol" Color="Red" Size="10" />

            <!-- A semi transparent blue fill, with blue border, thickness of 2. -->
            <esri:SimpleFillSymbol x:Key="BufferSymbol" Color="#660000FF" Style="Solid">
                    <esri:SimpleLineSymbol Color="Blue" Width="2" />


        <!-- Add a MapView. -->
        <esri:MapView x:Name="MapView1" WrapAround="True" MouseDown="mapView_MouseDown">

            <!-- Add a Map.-->
            <esri:Map x:Name="Map1">

                <!-- Add a backdrop ArcGISTiledMapServiceLayer. -->
                    ServiceUri="" />

                <!-- GraphicsLayer to hold the points the user clicks on the map. -->
                <esri:GraphicsLayer x:Name="myGraphicsLayer_UserInputPoints"/>

                <!-- GraphicsLayer to hold the polygons from the GeometryEngine.Buffer operation. -->
                <esri:GraphicsLayer x:Name="myGraphicsLayer_BufferPolygon"/>


        <!-- Add instructions on how to use the example code. -->
        <Border Background="White" BorderBrush="Black" BorderThickness="2" Margin="5" HorizontalAlignment="Right" VerticalAlignment="Bottom">
            <StackPanel Margin="3,3" Orientation="Horizontal">
                <TextBlock Text="Specify the buffer in miles and then click on the map:"
                           TextAlignment="Left" TextWrapping="Wrap" />
                <TextBox x:Name="TextBoxMiles" Text="5" Width="25" TextAlignment="right"/>


SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "GeometryEngine_Buffer.MainWindow" to be just "MainWindow".

namespace GeometryEngine_Buffer

    public partial class MainWindow : System.Windows.Window
        public MainWindow()

            // Set the initial extent (via the InitialViewpoint Property) of the backdrop ArcGIStiledMapServiceLayer to the Dallas/Fort Worth area.
            Esri.ArcGISRuntime.Geometry.Geometry myGeometry = new Esri.ArcGISRuntime.Geometry.Envelope(-10863035.97, 3838021.34, -10744801.344, 3887145.299);
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myGeometry);

        private void mapView_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                // Convert the screen point to the map point.
                System.Windows.Point myUIPointLocation = e.GetPosition(MapView1);
                Esri.ArcGISRuntime.Geometry.MapPoint myMapPoint = MapView1.ScreenToLocation(myUIPointLocation);

                // Get the buffer size from the user.
                double myBufferInMiles = System.Convert.ToDouble(TextBoxMiles.Text);

                // Create a variable to be the buffer size in meters. There are 1609.34 meters in one mile.
                double myBufferInMeters = myBufferInMiles * 1609.34;

                // Get a buffer polygon from the GeometryEngine Buffer operation. 
                // Note: the input distance to the Buffer operation is in meters. This is because the backdrop ArcGISTiledMapServiceLayer set the MapView's 
                // SpatialReference to WKID=102100, units=esriMeters.
                Esri.ArcGISRuntime.Geometry.Geometry myGeometryBuffer = Esri.ArcGISRuntime.Geometry.GeometryEngine.Buffer(myMapPoint, myBufferInMeters);

                // Show geometries on map.
                if (myGraphicsLayer_UserInputPoints != null)
                    // Get point symbol defined in XAML and apply it to the user clicked location; then add the map point to the graphics layer.
                    Esri.ArcGISRuntime.Symbology.Symbol myPointSymbol = (Esri.ArcGISRuntime.Symbology.Symbol)(layoutGrid.Resources["PointSymbol"]);
                    myGraphicsLayer_UserInputPoints.Graphics.Add(new Esri.ArcGISRuntime.Layers.Graphic(myMapPoint, myPointSymbol));

                    // Get polygon symbol defined in XAML and apply it to the buffer graphic; then add the buffer polygon to the graphics layer.
                    Esri.ArcGISRuntime.Symbology.Symbol myPolygonSymbol = (Esri.ArcGISRuntime.Symbology.Symbol)(layoutGrid.Resources["BufferSymbol"]);
                    myGraphicsLayer_BufferPolygon.Graphics.Add(new Esri.ArcGISRuntime.Layers.Graphic(myGeometryBuffer, myPolygonSymbol));
            catch (System.Exception ex)
                // Display an error message if there is a problem generating the buffer polygon.
                System.Windows.MessageBox.Show(ex.Message, "Geometry Engine Failed!");