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.
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?
UPDATE II
I am still working on the issue. My exact workflow looks like this:
- Create the line layer
- Create line intersections (Vector --> analysis tools --> line intersections)
- Split with lines (line layer is split at intersection points)
- field calculator (active layer is the "Split" line-layer): create "type" integer field using:
array_length( overlay_touches( 'line_layer', $geometry ) )
Remaining problems:
- wrong calculations (see results in the image "0" or "2 / 3")
- 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?




Delete duplicate geometriesas well, as written in my example workflow. Of course, linking your actual data would be best if you want GIS SE users to help you with your usecase. :) – winnewoerp Dec 09 '23 at 21:37Snap geometries to layerbetween steps 5 and 6 of my workflow might help here. – winnewoerp Dec 17 '23 at 12:21