Perform spatial operations
Find the union, intersection, or difference of two geometries.
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.
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.
- Create a
GraphicsOverlayand add it to the
- Define a
- Add the overlapping polygons to the graphics overlay.
Perform spatial relationships between the polygons by using the appropriate operation:
GeometryEngine.Union(geometry1, geometry2)- This method returns the two geometries united together as one geometry.
GeometryEngine.Difference(geometry1, geometry2)- This method returns any part of Geometry2 that does not intersect Geometry1.
GeometryEngine.SymmetricDifference(geometry1, geometry2)- This method returns any part of Geometry1 or Geometry2 which do not intersect.
GeometryEngine.Intersection(geometry1, geometry2)- This method returns the intersection of Geometry1 and Geometry2.
- Use the geometry that is returned from the method call to create a new
Graphicand add it to the graphics overlay for it to be displayed.
analysis, combine, difference, geometry, intersection, merge, polygon, union
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="ArcGISRuntimeXamarin.Samples.SpatialOperations.SpatialOperations" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"> <Grid> <esriUI:MapView x:Name="MyMapView" /> <Frame Margin="30" Padding="10" BackgroundColor="WhiteSmoke" HorizontalOptions="CenterAndExpand" VerticalOptions="Start" WidthRequest="275"> <StackLayout> <Label Text="Select a spatial operation:"> <Label.TextColor> <OnPlatform x:TypeArguments="Color"> <On Platform="Android" Value="DarkGray" /> </OnPlatform> </Label.TextColor> </Label> <Picker x:Name="SpatialOperationComboBox" Margin="0,5" VerticalOptions="CenterAndExpand" SelectedIndexChanged="SpatialOperationComboBox_SelectedIndexChanged" WidthRequest="253"> <Picker.BackgroundColor> <OnPlatform x:TypeArguments="Color"> <On Platform="Android" Value="DarkGray" /> </OnPlatform> </Picker.BackgroundColor> </Picker> <Button x:Name="ResetOperationButton" Clicked="ResetOperationButton_Clicked" Text="Reset operation" WidthRequest="253" /> </StackLayout> </Frame> </Grid> </ContentPage>