In the recipes so far, we routed from one starting point to one destination point. Another use case is when we want to compute routes that connect a sequence of points, such as the points in a GPS track. In this recipe, we will use the point layer to route processing script to compute a route for a point sequence. At its core, this script uses the same idea that was introduced in the previous recipe, Calculating the shortest paths with the QGIS network analysis library, but this computes several shortest paths one after the other.
To follow this recipe, load network_pgr.shp and sample_pts_for_routing.shp, which contains a point layer that should be routed from the sample dataset.
Additionally, you need to get the point layer to route script from https://raw.githubusercontent.com/anitagraser/QGIS-Processing-tools/master/2.6/scripts/point_layer_to_route.py and save it in the Processing script folder, which is set to C:\Users\youruser\qgis2\processing\scripts (on Windows), /home/youruser/.qgis2/processing/scripts (on Linux), and /Users/youruser/.qgis2/processing/scripts (on Mac) by default. Alternatively, save the point layer to route to the folder configured in the Processing menu under Options | Scripts | Scripts folder.
To compute the route between the input points, you need to perform the following tasks:

The point layer to route tool uses the QGIS network analysis library. We already discussed the basic use of this library in the previous recipe, Calculating the shortest paths with the QGIS network analysis library. The main difference is that we now have to handle more than two points. Therefore, the script fetches all points from the input point layer and ties or matches them to the graph:
points = [] features = processing.features(point_layer) for f in features: points.append(f.geometry().asPoint()) tiedPoints = director.makeGraph(builder, points)
For each pair of consecutive points, the script then computes the route between the two points just like we did in the Calculating the shortest paths with the QGIS network analysis library recipe:
point_count = point_layer.featureCount() for i in range(0,point_count-1): # compute the route between two consecutive points
The resulting route line layer contains one line feature for each consecutive point pair.
Of course, you can also use the point layer to route tool to route between only two points as well.
There is also a version of this script, which takes one-way information into account at https://raw.githubusercontent.com/anitagraser/QGIS-Processing-tools/master/2.2/scripts/point_layer_to_route_with_oneways.py.