Spatial relationships

View inAndroidFormsUWPWPFWinUIiOSView on GitHubSample viewer app

Determine spatial relationships between two geometries.

Image of spatial relationships

Use case

In case of a natural disaster, emergency services can represent the affected areas using polygons. By determining the spatial relationships between these and any other existing features such as populated areas, infrastructure, or natural resources, it is possible to quickly determine which of the existing features might be affected or is in further danger, helping to assess risk and define further action.

How to use the sample

Select one of the three graphics. The tree view will list the relationships the selected graphic has to the other graphic geometries.

How it works

  1. Get the geometry from two different graphics. In this example the geometry of the selected graphic is compared to the geometry of each unselected graphic.
  2. Use the methods in GeometryEngine to check the relationship between the geometries, e.g. contains, disjoint, intersects, etc. If the method returns true, the relationship exists.

Relevant API

  • Geometry
  • GeometryEngine
  • GeometryEngine.Contains
  • GeometryEngine.Crosses
  • GeometryEngine.Disjoint
  • GeometryEngine.Intersects
  • GeometryEngine.Overlaps
  • GeometryEngine.Touches
  • GeometryEngine.Within
  • GeometryType
  • Graphic
  • Point
  • Polygon
  • Polyline

Tags

geometries, relationship, spatial analysis

Sample Code

SpatialRelationships.xamlSpatialRelationships.xamlSpatialRelationships.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<UserControl x:Class="ArcGISRuntime.WPF.Samples.SpatialRelationships.SpatialRelationships"
             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>
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel>
                <TextBlock FontWeight="SemiBold"
                           Text="Tap a graphic to see its relationship with the others."
                           TextAlignment="Center"
                           TextWrapping="Wrap" />
                <TreeView Margin="0,5,0,0">
                    <TreeView.Items>
                        <TreeViewItem x:Name="PointTreeEntry" Header="Point" />
                        <TreeViewItem x:Name="PolylineTreeEntry" Header="Polyline" />
                        <TreeViewItem x:Name="PolygonTreeEntry" Header="Polygon" />
                    </TreeView.Items>
                </TreeView>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.