I have a network with previously calculated and direction-dependent travel time for each edge (speed_fw for drawing direction and speed_bw for against drawing direction). I prepare the network in QGIS as proposed within this answer, i.e. I double the geometry of the network with a forward and backward version of each edge.
The Shortest Path (Point to Point) algorithm outputs a cost field which contains the distance traveled in meters for the shortest path option and the time traveled in decimal hours for the fastest path option. I need distance and duration for both cases. Obtaining the distance for a fastest route is quite simple because the length can just be calculated using the field calculator (when not considering elevation for exact length calculation). But what if I need the time traveled for a shortest route option?
I would like to know if there is a simpler way to do this in QGIS than this workflow:
- Compute the shortest route between starting point A and destination point B.
- Rename
costcolumn todistance. - Intersect the underlying network (input layer) with the calculated shortest path (overlay layer), resulting in a "network" that only contains all edges of the previously calculated shortest path from A to B.
- Compute the fastest route using the intersected layer (using the
speedfield extracted fromspeed_fwandspeed_bwfor the doubled network). - Delete all fields except the
costfield for the resulting route layer and rename the field tohours. - Add an
hh:mm:ssfield for the duration in hours, minutes, and seconds and calculate the value from the decimalhoursfield using an appropriate formula. - Intersect the original shortest path with the attributively modified fastest path and save it to disk. It now contains the fields
start,end,distance,hours, andhh:mm:ss(see screenshot).
In step 3 it is important to not swap input and overlay layers. This leads to wrong results for travel time calculation as the features from the overlay layer are being modified.
