Generate convex hull polygon(s) from multiple input geometries.
Use case
Creating a convex hull allows for analysis to define the polygon with the least possible perimeter that encloses a group of geometric shapes. As a visual analogy, consider a set of nails in a board where the convex hull is a rubber band stretched around the outermost nails.
How to use the sample
Tap the 'Create Convex Hull' button to create convex hull(s) from the polygon graphics. If the 'Union' checkbox is checked, the resulting output will be one polygon being the convex hull for the two input polygons. If the 'Union' checkbox is un-checked, the resulting output will have two convex hull polygons - one for each of the two input polygons. Tap the 'Reset' button to start over.
How it works
- Create an
Map
and display it in aMapView
. - Create two input polygon graphics and add them to a
GraphicsOverlay
. - Call
GeometryEngine.ConvexHull(inputGeometries, boolean)
, specifying a list of geometries for which to generate the convex hull. Set the boolean parameter totrue
to generate a convex hull for the union of the geometries. Set it tofalse
to create a convex hull for each individual geometry. - Loop through the returned geometries and add them as graphics for display on the map.
Relevant API
- GeometryEngine.ConvexHull
- Graphic.ZIndex
- GraphicsOverlay
Tags
analysis, geometry, outline, perimeter, union
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.ConvexHullList.ConvexHullList"
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>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label x:Name="ConvexHullListInstructionsLabel"
Grid.Row="0"
FontSize="Small"
Text="Click the 'ConvexHull' button to create convex hull(s) from the polygon graphics. If the 'Union' checkbox is checked, the resulting output will be one polygon being the convex hull for the two input polygons. If the 'Union' checkbox is un-checked, the resulting output will have two convex hull polygons - one for each of the two input polygons." />
<StackLayout Grid.Row="1" Orientation="Horizontal">
<Label Text="Union:" />
<Switch x:Name="ConvexHullListSwitch" IsToggled="True" />
</StackLayout>
<Button x:Name="ConvexHullListButton"
Grid.Row="2"
Clicked="ConvexHullListButton_Clicked"
Text="Convex Hull" />
<Button x:Name="ResetButton"
Grid.Row="3"
Clicked="ResetButton_Clicked"
Text="Reset" />
<esriUI:MapView x:Name="MyMapView" Grid.Row="4" />
</Grid>
</ContentPage>