Find closest facility to an incident (interactive)

View inQMLC++
View on GitHub
Sample viewer app

Find a route to the closest facility from a location.

screenshot

Use case

Quickly and accurately determining the most efficient route between a location and a facility is a frequently encountered task. For example, a paramedic may need to know which hospital in the vicinity offers the possibility of getting an ambulance patient critical medical care in the shortest amount of time. Solving for the closest hospital to the ambulance's location using an impedance of "travel time" would provide this information.

How to use the sample

Click near any of the hospitals and a route will be displayed from that clicked location to the nearest hospital.

How it works

  1. Create a ClosestFacilityTask using an Url from an online service.
  2. Get a ClosestFacilityParameters from this task, using createDefaultParameters.
  3. Add a list of facilities to the task parameters, using ClosestFacilityParameters::setFacilities(const QList<Facility>& facilities);.
  4. Add an incident to the parameters, using ClosestFacilityParameters::setIncidents(const QList<Incident>& incidents);.
  5. Get the ClosestFacilityResult from solving the task with parameters: , ClosestFacilityTask::solveClosestFacility(const ClosestFacilityParameters& closestFacilityParameters);.
  6. Get the ranked list of the indices of the closest facilities to the incident, ClosestFacilityResult::rankedFacilities(int incidentIndex) const;.
  7. Get the index of the closest facility (e.g. the first index in the ranked list).
  8. Find the closest facility route, ClosestFacilityResult::route(int facilityIndex, int incidentIndex) const;.
  9. Display the route on the MapView:
  10. create a Graphic from the route geometry, new Graphic(route.routeGeometry(), this).
  11. add graphic to GraphicsOverlay which is attached to the mapview.

Relevant API

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

Tags

incident, network analysis, route, search

Sample Code

ClosestFacility.qmlClosestFacility.cppClosestFacility.h
                                                   
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// [WriteFile Name=FindClosestFacilityToAnIncidentInteractive, Category=Routing]
// [Legal]
// Copyright 2017 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.Samples 1.0

ClosestFacilitySample {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    // add a mapView component
    MapView {
        anchors.fill: parent
        objectName: "mapView"
    }

    BusyIndicator {
        anchors.centerIn: parent
        running: busy
    }

    Dialog {
        modal: true
        x: Math.round(parent.width - width) / 2
        y: Math.round(parent.height - height) / 2
        standardButtons: Dialog.Ok
        title: "Route Error"
        visible: text.length > 0
        property alias text : textLabel.text
        Text {
            id: textLabel
            text: message
        }
    }
}

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