View in MAUI WPF WinUI View on GitHub
import InlineCode from "@esri-dx/starship-doc-components/components/InlineCode.astro";

Find the union, intersection, or difference of two geometries.

Image of perform spatial operations

Use case

The different spatial operations (union, difference, symmetric difference, and intersection) can be used for a variety of spatial analyses. For example, government authorities may use the intersect operation to determine whether a proposed road cuts through a restricted piece of land such as a nature reserve or a private property. When these operations are chained together, they become even more powerful. An analysis of food deserts within an urban area might begin by union-ing service areas of grocery stores, farmer’s markets, and food co-ops. Taking the difference between this single geometry of all services areas and that of a polygon delineating a neighborhood would reveal the areas within that neighborhood where access to healthy, whole foods may not exist.

How to use the sample

The sample provides an option to select a spatial operation. When an operation is selected, the resulting geometry is shown in red. The ‘reset operation’ button undoes the action and allow selecting a different operation.

How it works

  1. Create a
    and add it to the
    .
  2. Define a
    of each
    .
  3. Add the overlapping polygons to the graphics overlay.
  4. Perform spatial relationships between the polygons by using the appropriate operation:
    • - This method returns the two geometries united together as one geometry.
    • - This method returns any part of Geometry2 that does not intersect Geometry1.
    • - This method returns any part of Geometry1 or Geometry2 which do not intersect.
    • - This method returns the intersection of Geometry1 and Geometry2.
  5. Use the geometry that is returned from the method call to create a new
    and add it to the graphics overlay for it to be displayed.

Relevant API

  • Geometry
  • GeometryEngine
  • GeometryEngine.Difference
  • GeometryEngine.Intersection
  • GeometryEngine.SymmetricDifference
  • GeometryEngine.Union
  • Graphic
  • GraphicsOverlay

Tags

analysis, combine, difference, geometry, intersection, merge, polygon, union

Sample Code

SpatialOperations.xaml SpatialOperations.xaml SpatialOperations.xaml.cs
<UserControl x:Class="ArcGIS.WinUI.Samples.SpatialOperations.SpatialOperations"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Border Width="275"
Margin="30"
Padding="10"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Background="White"
BorderBrush="Black"
BorderThickness="1">
<StackPanel>
<TextBlock Text="Select a spatial operation:" />
<ComboBox x:Name="SpatialOperationComboBox"
Width="253"
Margin="0,5"
SelectionChanged="SpatialOperationComboBox_SelectionChanged" />
<Button x:Name="ResetOperationButton"
Width="253"
Click="ResetOperationButton_Click"
Content="Reset operation" />
</StackPanel>
</Border>
</Grid>
</UserControl>