QGIS – How to Merge Lines with Same Name Attribute and Intersection

attribute-joinsintersectionmergeqgis

I have a polygon layer that has lines showing rivers. A river with the same name attribute might be consisted of a few lines touching each other. For example, in the image below, the river consists of 4 separate lines (with the same name in the name attribute column). The small line shown in red belongs to another river with a different name.

enter image description here

I need to merge the lines with the same names together and I know ways such as merge, join by attribute etc, however I cannot simply use merging by same name because it can happen that a line belonging to the same river (thus having the same name attribute) does not intersect with the rest of the river and cannot be merged into other lines.
Is there a way in QGIS 3.22.5 to unite the lines belonging to same river together (having same name attribute), but only those ones which touch in one point?

Dissolve window in QGIS 3.22:
enter image description here
Advanced window:
enter image description here

Best Answer

Use the QGIS Dissolve tool, set the parameters this way:

  • Input layer: your lines layer
  • Dissolve field(s): the river name
  • Keep disjoint features separate: True (this is in the advanced parameters section)

enter image description here

Optional if you don't see the Keep disjoint features separate option, dissolve and then run the Multipart to single parts tool.