1

I have a layer representing hydraulic network and I would like to merge the lines when they are connected to each other at their start/end vertex.

In the picture below , I merged the lines manually by selecting the lines and using the tool 'Merge selected feature'. I would like to generalise the process to integrate it in a model builder.

manually merged line

I tried using 'Dissolve' then 'Multipart to singlepart' but this is not working. When lines have multiple branches, each of them becomes a new feature after splitting to singlepart (as in the picture in this thread)

I also tried using a 'Buffer' (with dissolve option activated) and then 'Joining by location' the lines within the buffer. This work for the lines in blue in the picture, however it doesn't work for the green and orange one because the dissolved buffer is joined where the green and orange lines are overlapping.

I tried to create a dissolved buffer that would except when lines overlap but no success.

I am working with QGIS 3.16.3

2
  • A line is composed of 1 start and 1 end point, so if you want a Y shaped geometry, it has to be a multi-line
    – JGH
    Commented Mar 14, 2021 at 12:16
  • Well noted. This explains why I cannot use multipart to single part function. Then how can I separate the unique feature, obtained using dissolve function, into three (in our example) independent multilines ? Commented Mar 14, 2021 at 12:39

1 Answer 1

3

You can use the algorithm Service area (from layer):

  1. From your lines, extract vertices (Menu Gector / Geometry Tools / Extract vertices) - see screenshot 1 below.

  2. Open Menu Processing / Toolbox / Service area (from layer). Set your lines as Vector layer representing network and the vertices from step 1 as Vector layer with start points. Set the Path type to calculate to shortest and set Travel cost (distance for Shortest, time for Fastest to the maximum possible (999999999.000000 in my case). Run the tool (see screenshot 2 below).

  3. Run Menu Processing / Toolbox / Delete duplicate geometries. The resulting layer is what you're looking for - see screenshot 3.

Screenshot 1: This is my original hydraulic_network layer - the separate lines are in different colors and labeled by numbers. To make it clear where the lines start/end, I added the big white dots. The small red dots are the vertices created in step 1: enter image description here

Screenshot 2: Service area (from layer) dialog window:

enter image description here

Screenshot 3: this is how the result looks like: enter image description here

1
  • This is wonderful ! Amazing ! It is exactly what I have been searching for days. Thank you very much. Commented Mar 15, 2021 at 11:00

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.