Find routes from several locations to the respective closest facility.
Use case
Quickly and accurately determining the most efficient route between a location and a facility is a frequently encountered task. For example, a city's fire department may need to know which fire stations in the vicinity offer the quickest routes to multiple fires. Solving for the closest fire station to the fire's location using an impedance of "travel time" would provide this information.
How to use the sample
Click the button to solve and display the route from each incident (fire) to the nearest facility (fire station).
How it works
- Create a
ClosestFacilityTaskusing a URL from an online service. - Get the default set of
ClosestFacilityParametersfrom the task:closestFacilityTask.CreateDefaultParametersAsync(). - Build a list of all
FacilitiesandIncidents:- Create a
FeatureTableusingServiceFeatureTable(Uri). - Query the
FeatureTablefor allFeaturesusingQueryFeaturesAsync(queryParameters). - Iterate over the result and add each
Featureto theList, instantiating the feature as aFacilityorIncident.
- Create a
- Add a list of all facilities to the task parameters.
- Add a list of all incidents to the task parameters.
- Get
ClosestFacilityResultby solving the task with the provided parameters. - Find the closest facility for each incident by iterating over the list of
Incidents. - Display the route as a
Graphicusing theclosestFacilityRoute.RouteGeometry.
Relevant API
- ClosestFacilityParameters
- ClosestFacilityResult
- ClosestFacilityRoute
- ClosestFacilityTask
- Facility
- Graphic
- GraphicsOverlay
- Incident
Tags
incident, network analysis, route, search
Sample Code
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.ClosestFacilityStatic.ClosestFacilityStatic"
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 Style="{StaticResource BorderStyle}">
<StackPanel>
<Button Name="SolveRoutesButton"
Margin="0,5"
HorizontalAlignment="Stretch"
Click="SolveRoutesClick"
Content="Solve route"
IsEnabled="false" />
<Button Name="ResetButton"
HorizontalAlignment="Stretch"
Click="ResetClick"
Content="Reset"
IsEnabled="false" />
</StackPanel>
</Border>
</Grid>
</UserControl>