QGIS Dissolve – Dissolving Line Segments in QGIS if They Touch and Fall Within Same Class

dissolveqgisselect-by-attribute

I have line segments that have the following 3 attributes (Class, start_point, end_point).
I would like to merge/dissolve line segments that fall within the same class if they intersect (touch).

i.e. if the end_point of one line segment and the start_point of another line segment are the same (similar values).
(NB. I would like to dissolve lines with the same class value.
The dissolve field can also be a new field which will be generated when streams meet the above condition: ie they fall within the same class as well as the end_point of one segment = start_point of another segment)

Stream segments that should and others that should not be dissolved
The circled numbers represent the class (order) of the streams. Each segment has a corresponding class number as shown. The segments circled in red should be dissolved separately. The same should be done for the segments circled in green. Each segment has a start_point and an end_point. For example for the segments in yellow the end_point of one segment and the start_point of the other coincide.

The lower segment circled in red should not be dissolved with the lower segment circled in green because only their end_points coincide.

How can I proceed to do this in QGIS?

Best Answer

It all depends what are your data looking like. One easy way is to use two steps:

  1. Vector - Geoprocessing tools - Dissolve (dissolve everything with the same class)
  2. Vector - Geometry tools - Multipart to singleparts (will brake lines which are not touching to single lines)

Please be aware this way the table values - start_point and end_point for lines after these steps will not make much value anymore. Also the result in this way will be dissolved lines if their start and end points touches of always exactly 2 lines. If they are touching out of start/end points, crossing or multi-touching (typically Y cross), these won't be dissolved after second step.

Related Question