6

I want to know the orientation (relative to North) of a bay. The idea is, if I draw a line along a coast, and it crosses the bay mouth, I want the direction of the line perpendicular to that line (as shown in the pic). I want the orientation of the black line.

enter image description here

I'm thinking there must be a simple way to do this, but I'm not able to figure it out. I've used the "New Shape File" and "Add line Feature" (to make the green line), but I don't know how to make a line perpendicular to it, or how to read the orientation (I drew the black line in GIMP). I'm a total beginner in QGIS.

I am working with QGIS 3.16.10-Hannover version.

6
  • Some 12-15, I can do it manually, if that's why you're asking. The results would ideally be stored as a table, with the bay name in one column and orientation in the other one.
    – Marin
    Sep 13 at 8:17
  • To draw perpendicular lines in QGIS see: gis.stackexchange.com/q/380361/88814
    – Babel
    Sep 13 at 8:21
  • A problem I see is how to define "bay" so that QGIS can recognize it as such. I guess using concave or convex hulls and defining a minimum threshold for the water-area covered by it could be an approach. Or do it manually.
    – Babel
    Sep 13 at 8:25
  • Since there are not so many of them I think manually would be simpler.
    – Marin
    Sep 13 at 8:26
  • 2
    The azimuth of your manually drawn line is what you want to know. Add 90° to it, and you get the orientation of the perpendicular line.
    – Erik
    Sep 13 at 8:29
9

The angle of a simple two-point line segment in QGIS can be obtained with the main_angle() function. Open the attribute table and use the expression box at the top to set an attribute column (which you may need to create) to main_angle($geometry):

enter image description here

The angle at right angles is then that plus 90° degrees, so you can get that with 90 + main_angle($geometry) which I've stored in another column here.

Note that this direction could be into the bay or out of the bay, since there's no sense in the line segment of which side the bay is, unless you've consistently created your lines so that for example the bay is on the left of the line segment as seen from start to finish.

Also adding 90 can result in values outside (0,360), so you may need to reduce the result to that range using %, giving a final expression:

(90 + main_angle($geometry)) % 360

There's an azimuth() function that takes two points, so equivalently to main_angle($geometry) you can use azimuth(point_n($geometry, 1), point_n($geometry, 2)) for a simple two-vertex line segment. But that might break if you've accidentally digitised two coincident points at the start of your line. main_angle will cope with that and return the obvious angle of the line.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.