I have a polyline layer (Layer_A) in QGIS that represents entities (street crossings) that either consist of a single feature or are split into two or more features. The entities may also touch at their endpoints. I want to join the lines that belong to the same entity into one feature, but there is no attribute that I can use for that. So I need a geometry-based approach.
My current approach is the following:
- Extract all Layer_A endpoints using Extract specific vertices tool and vertex indices
0,1. - Extract all intermediate endpoints using Extract by expression tool with the following expression, where Layer_B is used to also exclude vertices where two Layer_A entities touch each other, as in that case they always touch Layer_B:
array_length(
overlay_touches(
'Layer_A',
$geometry
)
) > 1
AND
array_length(
overlay_touches(
'Layer_B',
$geometry
)
) = 0
This gives the following result (Layer_A purple, Layer_B green):
This shows that two Layer_A entities consist of two separate lines. The set of purple lines is supposed to be four entities (crossings) here. So I can't use Dissolve with the Keep disjoint features separate option.
I now want to iterate over the new point layer and join the lines together that touch the respective point, so that I have a single line for each entity in the end.
Here's the merging condition: Merge all features from Layer A (crossings) at their touching start/end points, except when they touch at least one feature from Layer_B (here: sidewalks) at this respective start/end point.
I look for solutions using geometry expressions either as an extension of my approach - or as a completely different solution.
Layer_A (crossings) sample data (Overpass query, export e.g. as GeoJSON)
Layer_B (sidewalks) sample data (Overpass query, export e.g. as GeoJSON)

Geometry by expressionstep and could useSplit with linesfor Layer_B in the end. Nevertheless, your solution seems to be highly valuable for other cases where Layer_B does not exist and the conditions require an approach based on vertices. – winnewoerp Dec 08 '23 at 12:18