I have a lot of points. Each one is connected to one or more lines. The lines have also more than one direction (max 4 directions). So how to figure out a method to identify the count of lines for each direction?

For example : I have a point layer that has one point (let's assume point_No. 1 ) this point is surrounded by 3 direction like direction 1 have 4 lines, direction 2 has 8 lines, and direction 3 have 12 line so the output of the code should be

Point No. | Direction 1 | Direction 2 | Direction 3 | Direction 4 output will be : 1 | 4 | 8 | 12

This is what I have enter image description here

What i tried is : 1- Explode lines on the lines layer enter image description here

2- apply expression on the Exploded lines layer enter image description here

3- this is the result after applying the expression enter image description here

4- when I tried to Delete duplicate geometries for the Exploded Layer there was an error Feature (544) from “Exploded” has invalid geometry. Please fix the geometry or change the “Invalid features filtering” option for this input or globally in Processing settings. Execution failed after 0.05 seconds but I fixed it by using fix geometries and then re-applying the expression so I got new line layer which is Cleaned enter image description here

4- then I Extract vertices on the original line layer so I get a new point layer which is Vertices enter image description here

5- Then I Delete duplicate geometries on the Vertices layer and a new layer is created which is Cleaned_Vertices enter image description here

6- The last step was running the expression using a field calculator and creating a new field called counts with the following expression array_to_string( overlay_touches( 'Cleaned_Vertices',"count" ) ) enter image description here

and this is what I got enter image description here

  • Not sure if I understand correctly. You need the count of overlapping lines that touch the respective point for each direction sparately? Are these exact line overlaps?
    – winnewoerp
    Dec 13, 2023 at 13:50
  • @winnewoerp Yes they overlapped the screenshot shows there are 8 or 12 or 4 which means there is 8 line or 12 lines...etc in the same path Dec 13, 2023 at 17:48
  • Ok, if it's even the same paths it may even possible to skip the Explode step of my answer.
    – winnewoerp
    Dec 13, 2023 at 18:45

1 Answer 1


Instead of using Python/PyQGIS, you could use different processing tools (or even create a graphical model), including some geometry expressions. If you have exactly overlapping lines (sharing the same vertices along the overlapping section) you could do the following:

  1. Use Explode lines processing tool on your original line layer
  2. Add an integer field count to each exploded line using the Field calculator algorithm with the following expression (replace 'exploded_line_layer' with the correct layer name):
) + 1
  1. Delete duplicate geometries using the result from the previous step
  2. Extract vertices of your original layer
  3. Delete duplicate geometries of your new point layer
  4. Add a new integer field counts to your cleaned point layer using the Field calculator processing tool using the following expression (replace 'cleaned_line_layer' with the correct layer name from the result of step 3):

The result with labels of count and counts fields then looks like this:


  • I'll give it a try Dec 13, 2023 at 17:48
  • I currently have two issues. The first, and most significant, problem is that some lines do not end with a point. Consequently, I am unsure of the method to ensure that all lines are split when they reach a point and do not cross through it. The second issue pertains to the last point. When attempting to add a new integer field 'counts' to my cleaned point layer using the Field Calculator processing tool with the following expression array_to_string(overlay_touches('cleaned_point_layer', 'count')) I observed that all the values in the 'counts' field are NULL. Dec 14, 2023 at 10:30
  • Can you provide example data or edit the question to give more details? It's hard to tell what's going wrong without having more information on your actual data. Maybe also add to the question what you have tried so far based on my answer including screenshots.
    – winnewoerp
    Dec 14, 2023 at 10:56
  • Let me clarify further. I have multiple points, and each of these points is connected by more than one line. As illustrated in the image in the question, this point is connected by 8 vectors on one side, 4 vectors on another side, and 12 vectors on yet another side. Therefore, I want to calculate the number of lines on each side, as explained in your response, but what you provided did not work for me Dec 15, 2023 at 11:26
  • I have edited the question and implemented all the solutions you provided. You can view the result now. Dec 15, 2023 at 15:10

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.