且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何计算PostGIS中两点之间的方位角?

更新时间:2023-02-09 19:51:53

首先要回答您的第二个问题,基本上有两种类型的方位角计算,一种是在平面坐标上完成的,另一种是在球体或椭球形上完成的,地理数据类型的情况. ***方位角文章对此进行了很好的解释.

To answer your second question first, there are basically two types of azimuth calculation, those done on planar coordinates, and those done on a sphere or spheroid, as is the case with the geography datatype. The wikipedia azimuth article explains this well.

在第一种情况下,计算非常简单,实际上只是两对点之间的atan.您可以在方法azimuth_pt_pt 中的 github上查看源代码. >.

In the first case the calculation is extremely simple, being essentially just the atan between the two pairs of points. You can see the source code on github in the method azimuth_pt_pt.

在第二种情况下,计算较为复杂,在一个球体上,您可以在

For the 2nd case, the calculation is a bit more complex, being on a sphere, and you can find the actual calculation again on github in the method spheroid_direction.

原因2不同是因为您使用的地理数据类型应在[-180,180],[-90,90]范围内.实际上,我很惊讶它没有给出错误.

The reason 2 is different is because you are using the geography datatype which should be in the range [-180,180],[-90,90]. Actually, I am surprised it doesn't give an error.

示例1和3本质上是相同的,因为您只是从一个坐标参考系切换到了另一个坐标参考系,所以这些点的相对方向不变.

Examples 1 and 3 are essentially the same, as you have simply switched from one coordinate reference system to another, so the relative direction of the points is unchanged.

没有正确的方法,但是,如果要使用geodetic coordinates,请使用geography datatype.

There is no correct way to do it, but if you want to use geodetic coordinates, then use the geography datatype.

请注意,两者之间存在差异

Note there is a difference between:

select degrees(
   st_azimuth(
       st_makepoint(0, 0)::geography, 
       st_makepoint(45, 45)::geography)
);

产生 35.4100589051161

同时

select degrees(
    st_azimuth(
       st_setsrid(st_makepoint(0, 0),4326),
       st_setsrid(st_makepoint(45, 45),4326))
);

收益 45 .一种是在平面上进行点对点方位角的测量,另一种是按照其功能名称的建议进行椭球体的方位测量.

yields 45. One is doing point to point azimuth on the plane, while the other is doing the spheroid azimuth, as suggested by their function names.