I'm currently using the Road Graph plugin to find the shortest path in a road network - however, I'd like to put this to a processing script (to be used in a model later) and the Road Graph Plugin has no API to be used in a model.

Is there a way to put the shortest path algorithm to a processing script and then use this script in a model?

I found some python scripts for networks/shortest path in the Python Cookbook and tried to put it to a processing script - but as I am a complete newbie with python I didn't get far..

enter image description here

The script should:

  • Take a roadnetwork (blue) and and a line vector layer (violet) as input
  • Put the start (green) - and endpoint (red) of the line as start and end of the path to be claculated
  • Use the intersections of the input line and the network as waypoints, that the path should follow
  • Find the shortest path (red ribbon) by routing through the network and save the path as vector layer

Can anybody help me with this script?

1 Answer 1


You can find multiple versions of routing scripts which use the QGIS network analysis library in my Github repository, e.g. https://github.com/anitagraser/QGIS-Processing-tools/blob/master/2.2/scripts/point_layer_to_route.py which converts an ordered set of points into a route.

None of the scripts use the intersections of an input line with the network. That's something you will have to add on your own.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.