sqlsql-servert-sqlgeometrybearing

Average bearing of a linestring


How can I compute a bearing that represent a non-straight linestring geometry?

For example, Given this linestring:

LINESTRING(-100.06372406847015 25.4583895045113,-95.14184906847015 30.197590679284158,-100.67895844347015 33.335334871825495,-95.40552094347015 36.576044042090466,-100.59106781847015 39.14304403636714,-95.40552094347015 41.61974326920709,-100.15161469347015 43.56067943577098,-95.66919281847015 45.87106856382069,-110.08325531847015 48.44030667059785,-85.38598969347015 48.73100364391479)

Which you can visualize here: http://arthur-e.github.io/Wicket/sandbox-gmaps3.html

enter image description here

The starting point (the first point in the linestring) is at the bottom of the map (starting in mexico).

I would expect the average/overall bearing of the line to be pointing north (~0 degrees)

Most calculations for the bearing of a line just take the start point and endpoint of the linestring and calculate it that way. Which is correct for a straight line with just 2 points.

I believe the way to do this for a linestring is to calculate the bearing for each POINT pair and the average them?

I am not sure if the methodology is right or if there is a better way (built in function or algorithm)


Solution

  • When you have segments lined up like you each segment represents a vector the total line is one resultant vector. You can find the angle of the vector finding the angle between the start point and the end point;

    The cartographical azimuth (in decimal degrees) can be calculated when the coordinates of 2 points are known in a flat plane (cartographical coordinates):

    enter image description here

    Source: https://en.wikipedia.org/wiki/Azimuth