Географические информационные системы и дистанционное зондирование

Calculating shortest path in QGIS using Road graph

Calculate the shortest path between two points on any polyline layer

Обсудить в форуме Комментариев — 97

Road graph is a C++ plugin for QGIS, that calculates the shortest path between two points on any polyline layer and plots this path over the road network.


  1. Installation notes
  2. How does it work
  3. Contacts

1. Installation notes

Source code of the plugin and ready to run binary files for both Windows and Linux are available via SVN.

Binary files

To work with plugin under Windows you need:

  1. download and install QGIS 1.6 or higher (read more)
  2. download the plugin and copy it to the QGIS plugins folder

To work with plugin under Linux you need:

  1. install QGIS 1.6 or higher. If packages for your distribution are not available — you need to compile QGIS from source
  2. download the plugin and copy it to the QGIS plugins folder. NOTE: plugin compiled under Debian Squeeze

We recommend to check md5sums after plugin download:

888c0ddf08384dde45a7e16ffeee6f8c roadgraphplugin.dll

After installing you should run QGIS and enable the Road graph plugin in Plugin manager («Modules → Manage plugins»).

Source code

You can obtain sources from SVN:

svn co road-graph

Build instructions are located in the file INSTALL (or for Russian).

2. How does it work

After plugin activation you will see additional panel on the left side of the main QGIS window:

Plugin panel

Main features:

  • calculate path, it's length and travel time;
  • optimize by length or by travel time;
  • export path in vector layer;
  • highlight roads directions (this is slow, used mainly for debug purposes and for the settings testing)

As a roads layer you can use any polyline vector layer in any QGIS supported format. Two lines with a common point are considered connected. WARNING: It is required to use layer CRS as project CRS while editing roads layer. This is due to the fact that recalculation of the coordinates between different CRS introduce some errors that can result in discontinuities, even when the «snapping» is used.

In the layer attribute table the folloving fields can be used:

  • speed on road section — numeric field;
  • direction — any type, that can be casted to string. Forward and reverse directions are correspond to the one-way road, both directions — two-way road.

If some fields don't have any value or do not exists — default values are used. You can change defaults and some plugin settings in plugin settings dialog.

Plugin settings

You can select start and end points with special buttons Select points tool near the fields or enter coordinates by hand.

Pressing «Calculate» button will run shortest path calculation using optimization criterion, selected in «Criterion» combobox. Button «Export» allow you exporting calculated path into new vector layer, and button «Clear» will erase all fields, remove points and calculated path from map camvas.

Here is screenshot of the plugin in action.

Plugin in the action

3. Contacts

If you want report a bug, make suggestion or have a question about the plugin, please contact us. Plugin author — Yakushev Sergey (stopa85).

Обсудить в форуме Комментариев — 97

Последнее обновление: September 09 2021

Creation date: 15.01.2011
Author(s): Alexander Bruy