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
ClosestFacilityTask
using a URL from an online service. - Get the default set of
ClosestFacilityParameters
from the task:closestFacilityTask.CreateDefaultParametersAsync()
. - Build a list of all
Facilities
andIncidents
:- Create a
FeatureTable
usingServiceFeatureTable(Uri)
. - Query the
FeatureTable
for allFeatures
usingQueryFeaturesAsync(queryParameters)
. - Iterate over the result and add each
Feature
to theList
, instantiating the feature as aFacility
orIncident
.
- Create a
- Add a list of all facilities to the task parameters.
- Add a list of all incidents to the task parameters.
- Get
ClosestFacilityResult
by solving the task with the provided parameters. - Find the closest facility for each incident by iterating over the list of
Incident
s. - Display the route as a
Graphic
using theclosestFacilityRoute.RouteGeometry
.
Relevant API
- ClosestFacilityParameters
- ClosestFacilityResult
- ClosestFacilityRoute
- ClosestFacilityTask
- Facility
- Graphic
- GraphicsOverlay
- Incident
Tags
incident, network analysis, route, search
Sample Code
<UserControl
x:Class="ArcGISRuntime.UWP.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"
Content="Solve route"
HorizontalAlignment="Stretch"
Margin="0,5"
Click="SolveRoutesClick"
IsEnabled="false" />
<Button Name="ResetButton"
Content="Reset"
HorizontalAlignment="Stretch"
Click="ResetClick"
IsEnabled="false" />
</StackPanel>
</Border>
</Grid>
</UserControl>