我试图完全理解方位 Angular 的概念,但遇到了一些不一致的地方(或者可能是我的错误)。
我向您展示了一些不匹配的示例,希望有人能向我解释这是如何工作的。
我在 EPSG:900913 中显示坐标,在 PostGIS 中并使用我自己的 JavaScript 函数。
我的功能
/* Difference between the two longitudes */
var dLon = lon2 - lon1;
/* Y value */
var y = Math.sin(dLon) * Math.cos(lat2);
/* X value */
var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
/* Calculates the azimuth between the two points and converts it to degrees */
var angle = Math.atan2(y, x) / Math.PI * 180;
示例
/* Same Y, not on the equator */
Point A: (-81328.998084106, 7474929.8690234)
Point B: (4125765.0381464, 7474929.8690234)
Result in PostGIS: 90 degrees
Result in my JS function: 74.232 degrees
/* Same Y, on the equator */
Point A: (-81328.998084106, 0)
Point B: (4125765.0381464, 0)
Result in PostGIS: 90 degrees
Result in my JS function: 90 degrees
我知道,在赤道上,水平线的方位 Angular 为 90(或 270)。认为如果你在赤道的北(或南)稍微画一条水平线,那么方位 Angular 就不再是 90 度了。但是... PostGIS 告诉我,当我们有相同的 Y 时,它总是 90 度。
此外,这 calculator还表明,当 Y != 0(不在赤道上)时,水平线的方位 Angular 不是 90 度。
如何正确?
谢谢
最佳答案
在您的示例中,您使用了 EPSG:900913,它是平面的、投影的并且以米为单位。这意味着使用的公式将是 atan2,当纬度相同时它总是 90,因为公式是:
方位 Angular = atan2(y1-y2, x1-x2)
第二部分将始终为 0,方位 Angular 为 90。因此,使用平面坐标,是的,对于具有相同纬度的坐标对,方位 Angular 将始终相同,这就是 Postgis 始终给出相同答案的原因使用 EPS 时:900913。
如果您切换到地理数据类型,并因此使用测地坐标,则情况不再如此。
例如:
select degrees(
st_azimuth(
st_makepoint(0, 10)::geography,
st_makepoint(90, 10)::geography));
在 Postgis 中给出 80.1318065,在您链接的计算器页面上给出 80.139。
对于给定的纬度,随着 x/经度靠得更近,值越接近 90。例如,
select degrees(
st_azimuth(
st_makepoint(0, 10)::geography,
st_makepoint(1, 10)::geography));
现在在 Postgis 中给出 89.9131737,在在线计算器中给出 89.333(差异稍大)。
所有这一切都是因为公式现在考虑了曲率,所以两个具有相同纬度的矢量的投影之间的 Angular 将不再是 90,赤道除外。
查看 Wikipedia azimuth 中的等式球体版本的文章。这应该很容易用 JavaScript 编写代码,并且应该为具有地理类型的 Postgis 提供类似的答案。
关于javascript - 赤道上的方位 Angular 等于赤道上的方位 Angular 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25529222/