线串的平均方位角

Average bearing of a 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)

你可以在这里形象化:http://arthur-e.github.io/Wicket/sandbox-gmaps3.html

起点(线串中的第一个点)在地图底部(从墨西哥开始)。

我希望这条线的 average/overall 方位指向北方(~0 度)

大多数直线方位角的计算只是采用线串的起点和终点并以此方式计算。这对于只有 2 个点的直线是正确的。

我认为对线串执行此操作的方法是计算每个 POINT 对的方位并计算它们的平均值?

我不确定方法是否正确,或者是否有更好的方法(内置函数或算法)

我得到的角度是向北,但我的北是90度,而我从你的角度得到的角度是84度左右,所以向北偏东。 注意:这可能不正确,但只是尝试。

我首先使用 split 得到单独的点,然后 xml 得到每个东点和北点, 然后重新排列数据,这样我就可以在同一行中看到每个点和下一个点。 然后计算增量,然后计算每个点之间的方位,最后是平均值。希望对你有帮助。

declare @data nvarchar(max)='-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'
declare @points table (seq int,x float,y float)

    ;with points as (select ROW_NUMBER() over (order by (select 1) desc) seq,* from string_split(@data,','))
    ,xmldata as (select points.seq,CONVERT(XML,'<Points><Point>'+ REPLACE(points.value,' ', '</Point><Point>') + '</Point></Points>') AS xmldataPoints
    from points),pointXY as (
    SELECT seq,
        xmldata.xmldataPoints.value('/Points[1]/Point[1]','float') AS [x],
        xmldata.xmldataPoints.value('/Points[1]/Point[2]','float') AS [y]
    FROM xmldata
    ),nextPoint as (
    select *,LEAD(x,1,null) over (order by seq) x2,LEAD(y,1,null)  over (order by seq) y2 from pointXY
    ),delta as (
    select *,(x2-x) dNorth,(y2-y) dEast from nextPoint
    ),bearing as (
    select * ,
    DEGREES(  IIF(dEast=0,
        IIF(dNorth<0,PI(),0),
        IIF(dEast<0,(-aTan(dNorth / dEast) + PI() / 2.0+ PI()),(-aTan(dNorth / dEast) + PI() / 2.0)))) bearing
    from delta
    )
    select AVG(bearing) from bearing

结果

84.5262691250142

当你像你一样排列线段时,每个线段代表一个向量,总线就是一个合成向量。你可以找到向量的角度找到起点和终点之间的角度;

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

来源:https://en.wikipedia.org/wiki/Azimuth