Find closest facility to multiple incidents (service)

View inAndroidFormsUWPWPFWinUIiOSView on GitHubSample viewer app

Find routes from several locations to the respective closest facility.

Image of find closest facility to multiple incidents service

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

  1. Create a ClosestFacilityTask using a URL from an online service.
  2. Get the default set of ClosestFacilityParameters from the task: closestFacilityTask.CreateDefaultParametersAsync().
  3. Build a list of all Facilities and Incidents:
    • Create a FeatureTable using ServiceFeatureTable(Uri).
    • Query the FeatureTable for all Features using QueryFeaturesAsync(queryParameters).
    • Iterate over the result and add each Feature to the List, instantiating the feature as a Facility or Incident.
  4. Add a list of all facilities to the task parameters.
  5. Add a list of all incidents to the task parameters.
  6. Get ClosestFacilityResult by solving the task with the provided parameters.
  7. Find the closest facility for each incident by iterating over the list of Incidents.
  8. Display the route as a Graphic using the closestFacilityRoute.RouteGeometry.

Relevant API

  • ClosestFacilityParameters
  • ClosestFacilityResult
  • ClosestFacilityRoute
  • ClosestFacilityTask
  • Facility
  • Graphic
  • GraphicsOverlay
  • Incident

Tags

incident, network analysis, route, search

Sample Code

ClosestFacilityStatic.xamlClosestFacilityStatic.xamlClosestFacilityStatic.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
24
25
26
27
<UserControl x:Class="ArcGISRuntime.WPF.Samples.ClosestFacilityStatic.ClosestFacilityStatic"
             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>
        <Grid>
            <esri:MapView x:Name="MyMapView" />
            <Border Style="{StaticResource BorderStyle}">
                <StackPanel>
                    <Button x:Name="SolveRoutesButton"
                            Height="30"
                            Margin="0,5"
                            HorizontalAlignment="Stretch"
                            Click="SolveRoutesClick"
                            Content="Solve Routes"
                            IsEnabled="False" />
                    <Button x:Name="ResetButton"
                            Height="30"
                            HorizontalAlignment="Stretch"
                            Click="ResetClick"
                            Content="Reset"
                            IsEnabled="False" />
                </StackPanel>
            </Border>
        </Grid>
    </Grid>
</UserControl>

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