6

I am trying to calculate the number of lines touching an intersection point to calculate the number of 3-way, 4-way (etc) intersections within my polyline layer. E. g. when 4 lines are connected to an intersection point, I expect the result to be '4' (etc.).

So what I imagine is the attribute table for the intersection point layer that displays for each point the "type of intersection" or "number of touching lines", so I can afterwards calculate the total number of different intersections.

Polyline layer with intersection points

What I have tried so far is the "split with lines" tool to make sure, that each line is split by each intersection point.

I added a new attribute to the intersection point layer ('type') and used the following code in the field calculator:

aggregate('line_layer', 'count', $id, intersects($geometry, geometry(@parent)))

Unfortunately, the results are either '0', '2', or '4', but only randomly correct.

Do you know a workflow using Python or the available tools in QGIS?

I am using QGIS 3.32.3-Lima.

UPDATE I

Using the expression from the answer below I am getting better results, but there are still some miscalculations. As you see in the newly added image, at the "3-way-intersections" (3 lines touching an intersection point) the result is "4". Also, on the lower left side, there is an intersection with 5 connecting lines (result=2) and so on. The labels in the image show the results. Am I missing something?

calculation results using the expression; wrong results at 3-way-intersections

UPDATE II

I am still working on the issue. My exact workflow looks like this:

  1. Create the line layer
  2. Create line intersections (Vector --> analysis tools --> line intersections)
  3. Split with lines (line layer is split at intersection points)
  4. field calculator (active layer is the "Split" line-layer): create "type" integer field using:

array_length( overlay_touches( 'line_layer', $geometry ) )

Remaining problems:

  1. wrong calculations (see results in the image "0" or "2 / 3")
  2. duplicated results (in your sample image there is only one result displayed at one intersection; In my case, the intersections are duplicated after calculation). Am I missing a step in between to avoid duplication?

QGIS project setup - label shows calculated intersections

8
  • 2
    Could you share your data? I think there's some issue with it that I did not take into account for my solution (see my edited answer including a screenshot).
    – winnewoerp
    Nov 13, 2023 at 9:39
  • 1
    By the way: What are "2-way intersections"? :)
    – winnewoerp
    Nov 13, 2023 at 9:59
  • What does "Create the line layer" mean in your UPDATE II process description? Do you create a line layer by drawing manually in editing mode? Or do you use a specific processing algorithm to generate the line layer (e.g. out of a larger network) to be used for the next steps?
    – winnewoerp
    Nov 27, 2023 at 12:50
  • In any case: Try "Dissolve" on your created line layer after step 1. Does this lead to a better or even correct result?
    – winnewoerp
    Nov 27, 2023 at 12:53
  • 1
    Thank you so much! It helped! Now it works perfectly :)
    – marla
    Dec 19, 2023 at 8:03

1 Answer 1

6

To count the touched split lines for each point, overlay_touches() can be used in combination with array_length().

The expression for creating the "type" integer field then looks like this:

array_length(
  overlay_touches(
    'line_layer',
    $geometry
  )
)

Here's a screenshot of an example result with correct type counts as expected (no "2" results).

Example output (OSM data)

To test my workflow with exactly the network data shown in the screenshot, do the following:

  1. Download the network data (Export --> GeoJSON download) or use other OpenStreetMap sample network data
  2. Load all LineString features as vector layer into a new QGIS project (and set project CRS to EPSG:3857 or a local metric one for a "nicer" projection, if you like)
  3. Run Dissolve on the imported layer
  4. Run Split with lines on the dissolved layer (as input and as split layers)
  5. Run Line intersections on the split layer (as input and as intersect layers)
  6. Run Delete duplicate geometries on the intersections point layer
  7. Use Field calculator to add the type field with the expression as described above, but with 'line_layer' replaced by your split layer name
  8. Select type field as label and you should see only numbers >= 3, probably with 3 and 4 quite often, no or few higher numbers, depending on your network structure
1
  • You are right, there should not be any 2-way intersections (I've edited that in the question). Your results look exactly what I am trying to achieve.
    – marla
    Nov 26, 2023 at 15:29

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.