1

I'd like to know how to choice the left or right direction starting from a point and following a network; in the processing shortest path (from starting point to vector points layer) of QGIS. In this tool, i noticed which there are the direction values to enter in the interface. I want to choice the direction, even if it's not the shortest way. Any suggestions?

1 Answer 1

1

If you expand the Advanced Parameters settings in shortest path tools, you have the possibility to define directions.

1. Default direction: forward

  1. Easiest is to use the line direction - the direction the line was drawn, from start to destination. If you set Default direction to Forward direction, the network can be used only in the direction the line was drawn. The result is what you want.

    Screenshot: the yellow line is the output of shortest path from start (red) to destination (blue), but only following the line direction (black arrows):

    enter image description here

    To see the line direction (drawing order), apply a symbol layer of type Arrow to get arrows like in the screenshot above.

2. Changing default direction to backward/both directions

You could also set Default direction to Backward or Both Directions.

3. Set individual direction for each line in attribute

More sophisticated, you can use an attribute that for each line adds an individual value that tells the shortest path tool in which direction the line can be used. In the network layer, create an attribute direction and set values of e.g. f (forward), b (backward) and both. Then select this field and define which values correspond to forward/backward/both directions.

Consider this example: arrows show the draw-direction, colors of the lines show the value of the direction attribute: blue=forward, red=backward, black=both. Yellow: output shortest path. The line can not follow the same path as in the screenshot above, since the red line is backward: it must be followed in the opposite direction of the arrows:

enter image description here

4. Reverse Line Direction

To permanently reverse line direction (draw order) without using attributes and thus to be able to stick to solution 1 from above, you can use the tool from Menu Processing > Toolbox > Reverse Line Direction, see documentation. You can also make a selection first and then run the tool for Selected features only.

6
  • Your answer is perfect, thanks a lot! But i'm in difficulty beacause some lines of the network was drawn in one direction and the others on the opposite; so if i use "forward direction" or "backward direction" in the default direction it doesn't work. Any suggestions to get only one direction in the network from a starting point to an ending point?
    – Mark
    Commented Sep 8, 2022 at 12:54
  • See solution no. 3 that adresses exactly this case: you can define for each individual line if direction should be forward or backward. Other option: use the tool Reverse line direction, see: docs.qgis.org/3.22/en/docs/user_manual/processing_algs/qgis/… (added as solution no. 4)
    – Babel
    Commented Sep 8, 2022 at 12:57
  • ok, but how can i choice to put "f" or "b" in a new column "direction" in the right way on was drawn the lines? How can i get the value of the direction of a line?
    – Mark
    Commented Sep 8, 2022 at 13:59
  • Added the information to see the drawing order at end of solution 1 - see updates answer.
    – Babel
    Commented Sep 8, 2022 at 14:17
  • It's obviously an useful way but i've 10000 records in my network. It's quite hard with only the symbology..
    – Mark
    Commented Sep 8, 2022 at 15:32

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.