1

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:

  1. Extract all Layer_A endpoints using Extract specific vertices tool and vertex indices 0,1.
  2. 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):

Sample data screenshot

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)

0

1 Answer 1

1
  1. Dissolve with the option Keep disjoint features separate activated.

  2. Get the points where layer A touches layer B, e.g. using overlay_touches().

  3. Split lines of layer A at these points using this approach.

3
  • Thank you. I tested it using this model (still incomplete). I get an error for "Geometry by expression": Error encountered while running Geometry by expression: Evaluation error: Cannot convert to geometry.
    – winnewoerp
    Commented Dec 8, 2023 at 9:08
  • Maybe there's a difference when using the expression here and not within the Geometry generator?
    – winnewoerp
    Commented Dec 8, 2023 at 9:16
  • 1
    It turned out that I didn't even need the Geometry by expression step and could use Split with lines for 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
    Commented Dec 8, 2023 at 12:18

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.