1

I need to calculate the best cycling route using selected attributes of the network layer as cost values. Using the "Shortest Path (Point to Point)" tool for network analysis in QGIS, how can I set the impedance (cost) based on two different attributes, depending on the direction in which paths are included into the route (forward or backward).

I only find the option to select shortest and fastest route and select a sinlge "speed" field. But I have sec_fw and sec_bw as fields that contain the direction-specific travel time of the path in seconds (values are different in many cases because of slope) and need to get the values from these fields for each path segment of a route.

2
  • 1
    How about duplicating the edges so that you have both forward and backward edges, set a flag field (forward/backward), and set the travel times for each edge respectively? Once you've done this, the "Shortest Path (Point to Point)" tool should be able to handle the rest May 11, 2023 at 4:13
  • Thank you, that sounds like a possible way to go. But how to I combine everything into one path then? The algorithm needs to know for each edge if it has to take the forward (drawing direction) value of the path or the backward (opposite to drawing direction) version.
    – winnewoerp
    May 11, 2023 at 4:57

1 Answer 1

2

Here's a rough approach. Let's assume a very basic network, with three points and three lines. Say you're looking for the Shortest Path (Point to Point) from A to B. The time in seconds in the forward direction is at the start of the arrow (based on the direction the arrow is pointing), and the time in seconds in the backward direction is towards the end of the arrow.

So on the A-B line, it's 10s from A to B and 2s from B to A.

enter image description here

The attribute table is as you have described.

enter image description here

First step is to clone the network layer twice - once for the forward paths (call the layer 'Forward'), the second for the backward paths (which we'll call 'Backward'). One easy way of doing this is to Select All Features and then run Extract selected features from Processing Tools.

Delete the 'sec_bw' field for the Forward layer, and add a direction field set to 'forward' for all features. Delete the 'sec_fw' field for the Backward layer, and add a direction field set to 'backward'. (Alternatively, just use the default values of 0/1 for forward/backward)

Rename the remaining sec_bw/sec_fw fields to sec (via the Properties -> Fields).

Merge the Forward and Backward layers (Merge vector layers). Add a 'speed' field - I calculated this as $length / 1000 / (sec / 3600)

Now you can run the Shortest Path (Point to Point) algorithm on the merged layer.

enter image description here

5
  • Thank you, Tom. This looks indeed very promising. (BTW: I forgot to mention that speed_fw and speed_bw are already there, so I included these fields into the workflow you proposed.) I think the addition of the Direction field for Forward and Backward layers can be omitted, as the "Merge vector layers" tool automatically creates a field with the source layer names. So this field can be used as the direction field.
    – winnewoerp
    May 12, 2023 at 5:07
  • Just one more thought: Are you sure that doubling the network geometry is the way to go for time/speed depending of the drawing direction in QGIS? I would have expected that there's a way to select a time/speed field for all edges that are part of the route in the drawing direction and to select another time/speed field for edges included against drawing direction. Is this possible in ArcGIS Pro?
    – winnewoerp
    May 12, 2023 at 5:15
  • I don't see an alternative using the Shortest Path (Point to Point) algorithm. There may be other solutions in QGIS eg plugins. If you want more answers, you may need to offer a bounty. If you want to ask about ArcGIS Pro, you should ask a separate question. Always best to keep questions focussed, and give as much information as possible in the initial question. May 12, 2023 at 6:46
  • I really appreciate your effort to present this useful solution for the presented case. And thanks for the hints regarding alternatives and good questions in GIS SA.
    – winnewoerp
    May 13, 2023 at 6:10
  • Here you can find a graphical model for QGIS that does exactly what has been described in the answer: directional_geometries_for_shortest_path.model3
    – winnewoerp
    Jun 22, 2023 at 23:14

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.