1

Let say, I have a country vector layer like Lebanon in this example, for us as humans we can easly see that the country extends the best not from north to south like Chile, or from east to west like Turkey but oblique from Northeast to Southwest.

If I calculate the centroid of Lebanon C as in image below, is there an approach or possibility to find the angle theta between the line passing through C and the vertical line North-South to fit the best like the orientation of the country?

I drawn the blue lines with paint to show my idea, see image below image

1 Answer 1

2

In later versions of QGIS, you can use the function main_angle in the field calculator.

main_angle($geometry)

enter image description here

enter image description here

From the help panel of the field calculator:

Function main_angle

Returns the angle of the long axis (clockwise, in degrees from North) of the oriented minimal bounding rectangle, which completely covers the geometry.

Note: the minimal bounding rectangle in the image was created for visualisation purposes using the function oriented_bbox

1
  • 1
    thank you so much, that was what I looked for
    – Khaled
    Commented Feb 8, 2023 at 22:04

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.