7

I am currently trying to calculate the angle between two lines or rather vectors (which are not touching) like in the picture shown below: enter image description here

In order to calculate the angle α, I think I will have to lengthen v1 somehow, so I get an intersection point of both vectors, like this:

enter image description here

Is there a way to do this within a python script (and how?) or can I do this with the field calculator of QGIS?

As I have two vector layers, I need this calculation more than one time and I will have to store the result into an attribute.

1
  • How are the lines related you are going to calculate the angle for? Do they have an attribute which holds the partner id, or do you need the calculation for lines having an (projected) intersection?
    – Detlev
    Commented Dec 26, 2017 at 20:20

1 Answer 1

9

Possible first step will be azimuth calculation by the Field calculator.

degrees(azimuth(start_point($geometry), end_point($geometry)))

enter image description here

To obtain the angle between them, there would be several options, for instance:

  • Save the attribute table as csv and calculate (v1.azimuth - v2.azimuth) by a spreadsheet software (Excel, Calc).
  • SQL syntax using JOIN by Virtual layer

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.