I have one vector layer of multiple polylines that intersect each other in QGIS.
What I want to do: calculate all intersections angles (2-ray, 3-ray, 4-ray and 5-ray types) in this vector layer.
What I did: I used the v.clean tool to split all polylines at the intersections.
I created a buffer at every intersection and clipped out the polylines. Then I assigned a unique “buffer ID” for the related intersections located within each buffer. The orientation of each line at an intersection was calculated with: degrees(azimuth(start_point($geometry), end_point($geometry)))

I have come this far. I think next step is to subtract the orientation value of a line feature from it’s adjacent line feature (e.g. clockwise from 0°) and so on until all intersection angles are calculated, then going on with the next buffer.

The problem: As you can see in the Screenshot and a section of the attribute table, the displayed IDs are not always in a clockwise (or counterclockwise) order. So, I don’t know how tell E.g. Excel or QGIS which value to subtract from which one.

Sorting the values by “Orientation” also doesn’t work always since e.g. ID1788 has 135° (should be 315°) but ID1790 has 208° Orientation of 227° corresponds to 47° (227°-180°)

E.g. ID1790 (208°) - ID1788(135°) = 73° (wrong intersection angle)
correction: ID1790 (208°) - ID1788(135°**+180**]) = (-)107°

I hope I was able to explain my problem clearly and maybe you have a solution approach for me. I also read this point-based approach, but I don’t know if it helps for my problem. (Calculating angle using three WGS 84 points and Angle at intersection point from two Lines )

Section of Attribute table with Line ID, BufferID and Orientation/Azimuth

Screenshot from the polylines with their buffer (purple)

1 Answer 1


To use azimuth in this way you must make sure that the startpoint parameter corresponds to the part of the line that is connected to the central axis (the hub).

Since azimuth() returns the clockwise angle (radian) from north, calling degrees(azimuth(startpoint,endpoint) on line 1788 from your example will only return 315 deg if startpoint is the hub. If you input the parameters backward (endpoint is the hub) you are taking the clockwise angle from north of a line that goes down and to the right, 135 deg.

One approach:

1) Create a small(er) buffer around the centroid of your current buffers -> BufferCenter

2) Use the following expression in QGIS Expression Editor to first check if start_point($geometry) is the hub node (intersects the smaller buffer), and swap points if it isn't.

if(intersects(start_point($geometry), geometry(get_feature('BufferCenter', 'BufferId', "bufferid"))),
  degrees(azimuth(start_point($geometry), end_point($geometry))),
  degrees(azimuth(end_point($geometry), start_point($geometry)))

Where: BufferCenter is the layer name from (1), BufferId is the id field on BufferCenter, and bufferid is the id field on the line layer.

Example below showing before (Angle) and after (Azimuth).

enter image description here

Now you can use your preferred tool to take the absolute value of the difference of any two Azimuth values sharing the same BufferId and get the positive angle between them.

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.