QGis shortest path network analysis tools

Two types of network analysis tools are available:

  • shortest or fastest path calculations
  • service area calculations

In network analysis with QGIS, shortest path refers to the shortest route between two given points in a road or transportation network. It’s about finding the optimal route that requires the least distance, time or resources to move from a specific starting point to a specific end point.

Shortest path analysis is used to calculate and visualize the most efficient route between two locations, taking into account network constraints such as distances, speed limits, one-way streets, etc. This analysis can be used in a wide range of applications. This analysis can be used in many fields, such as transport planning, logistics, route optimization, navigation and more.

In QGIS, there are several methods for calculating the shortest path, including the Dijkstra algorithm and the A* (A-star) algorithm. These algorithms use spatial data, such as the road network and road attributes, to determine the optimal path. Shortest path analysis can be performed using the “Network Analysis” tool or other specific tools available in QGIS, such as the “RoadGraph” plugin.

In network analysis with QGIS, a service area refers to a geographic zone that is covered or served by a specific transportation or distribution network. This can include elements such as roads, public transit lines, water or electricity networks, telecommunications infrastructures, etc.

The service area represents the geographical extent from which users can access the services or resources available via the network. It can be defined according to various criteria, such as maximum distance, travel time, network capacity, etc.

Service area analysis in QGIS enables you to map and analyze the areas covered by a specific network, which can be useful for making decisions about planning, equipment location, service accessibility, etc. This analysis makes it possible to visualize and quantify the geographical reach of a given network, which can facilitate decision-making in many areas, such as urban planning, transport, regional development, etc.

Shortest distance tools

To calculate a distance, you need one or more starting points and one or more finishing points. The tools available can take as start and end points

  • either points entered manually in the map window, referred to as “points” in the tool titles, or
  • or a layer of points, referred to as a “layer” in the tool titles.

We therefore have three shortest path tools:

  • Shortest path (from layer to point): for each point contained in the point layer (departure), we calculate the shortest path to a point entered by hand (arrival) on the map window;
  • Shortest path (point to point): enter a first point (departure) and a second (arrival) in the map window, and the tool will calculate the shortest path between the two;
  • Shortest path (point to layer): enter a first point (start) in the map window and calculate the shortest path to each point in the point layer (finish).

Service area tools.

There are two service area tools:

  • Service area (layer): given a distance (or travel time), the tool will calculate all possible routes from each point contained in the point layer;
  • Service area (point): given a distance (or travel time), the tool will calculate all possible routes from a point entered in the map window.

We’ll see an example with points entered on the map, as using a layer doesn’t change the possible options, only the result will be the sum of all point-to-point treatments.

Network analysis: Shortest path

shortest path processing parameters (point-to-point)

Network analysis: Simplest case – default settings

To run this process, simply fill in the first four fields:

  • the vector layer with our linear network
  • the type of path to be calculated (by default, the shortest path)
  • starting point
  • the end point

If you don’t have any other parameters to take into account (direction of traffic, speed limit), running the process will give you the desired route.

By clicking on the … button next to the start and end points, the window is cleared and a … is displayed.

result of shortest point-to-point path with QGis network analysis with default parameters

If you open the attribute table of the result layer, you’ll see a cost attribute representing the total distance of the route. If you’re working in geographic coordinates, the distance will be in degrees.

shortest path attribute table with cost field containing total distance

Network analysis: Case with one-way traffic

While the first case can easily be applied to a route in open country, in the city, failure to take account of authorized traffic directions often leads to useless results.

shortest path result without taking traffic direction into account

The route calculated in this way takes in several prohibited directions. To take traffic directions into account, we use the oneway attribute in OSM. A value of B indicates that the section is two-way, and a value of F indicates that the direction of traffic is the direction in which the section was digitized. A value of T indicates that the section cannot be used.

shortest path parameterization to use OSM oneway field

With these parameters, the result (in yellow) is consistent and respects traffic directions.

result of shortest path with traffic direction taken into account

Network analysis: the case of the fastest route

In the two previous examples, we chose the type of route = shortest route.

If we want to take speeds into account to find the fastest route, we have two possibilities.

The first is to choose the fastest route type and use the default speed from the shortest route tool parameters.

set shortest path with default traffic direction and speed

The tool uses this parameter as soon as the fastest route is requested AND no speed field is entered.

The route calculated will be the same as if the shortest route was requested, what will change is the cost attribute of the result, which will be expressed in hours rather than meters.

To take account of authorized speeds contained in OSM layers, you need to fill in the Speed field by selecting the maxspeed attribute. Be careful to display labels with section speeds, as this attribute is not always filled in. In this case, maxspeed has a value of 0. If you request the fastest route, sections with this value will be considered unusable and the result will be distorted or impossible.

set maxspeed in shortest path

In the following example, we calculate the shortest route without taking speed limits into account (in red) and the fastest route taking them into account (in yellow).

shortest path and fastest path with OSM maxspeed taken into account

Network analysis: Searching for a path from a point to a layer

Let’s take a look at the case where we want to find the nearest hospital. In this example, we have a starting point that we enter manually and we have the OSM layer with a filter to display only hospitals.

data for searching paths from a point to a point layer

We open the Shortest path process (from point to layer) and simply indicate which layer contains the arrival points and enter our starting point

parameters for finding the shortest path from a point to a layer

and the tool will calculate the shortest path between our starting point and each of the points in the destination layer.

result of the shortest path from a point to a layer

Since the Hospitals layer contains 78 entities, we have 78 calculated paths. If we open the attribute table and sort the cost field from smallest to largest, we have the routes sorted by length.

The closest hospital is the one with id 4356718789, 44.987 km from our starting point. Of course, all the options we’ve seen on the point-to-point examples (traffic direction, speed limit) can be used with the point-to-layer tool.

Si cet article vous a intéressé et que vous pensez qu'il pourrait bénéficier à d'autres personnes, n'hésitez pas à le partager sur vos réseaux sociaux en utilisant les boutons ci-dessous. Votre partage est apprécié !

Leave a Reply

Your email address will not be published. Required fields are marked *