ST_Azimuth — 返回两点之间直线的基于北方的方位角。
float ST_Azimuth(geometry origin, geometry target);
float ST_Azimuth(geography origin, geography target);
返回目标点距原点的方位角(以弧度为单位);如果两点重合,则返回 NULL。 方位角是从正 Y 轴(几何)或北子午线(地理)参考的正顺时针角度:北 = 0; 东北=π/4; 东=π/2; 东南=3π/4; 南= π; 西南5π/4; 西=3π/2; 西北 = 7π/4。
对于地理类型,方位角解决方案被称为反解大地测量问题。
方位角是一个数学概念,定义为参考矢量与点之间的角度,角度单位为弧度。 可以使用 PostgreSQL 函数 Degrees() 将结果值(以弧度表示)转换为度数。
For offsetting lines relative to their direction, use ST_OffsetCurve. For projecting a point by distance and bearing, use ST_Project.
可用性:1.1.0
增强:2.0.0 引入了对地理的支持。
增强:2.2.0使用 GeographicLib 对球体进行测量,以提高准确性和稳健性。 需要 PROJ >= 4.9.0 才能利用新功能。
几何方位角(以度为单位)
SELECT degrees(ST_Azimuth(ST_Point(25, 45), ST_Point(75, 100))) AS degA_B,
degrees(ST_Azimuth(ST_Point(75, 100), ST_Point(25, 45) )) AS degB_A;
dega_b | degb_a ------------------+------------------ 42.27368900609371 | 222.27368900609372
Compass direction labels can be computed from the azimuth.
WITH directions(deg) AS (VALUES
(0), (45), (90), (135), (180), (225), (270), (315)
),
bearings AS (
SELECT deg,
degrees(ST_Azimuth(ST_Point(0, 0),
ST_MakePoint(sin(radians(deg)),
cos(radians(deg))))) AS azimuth
FROM directions
)
SELECT deg,
round(azimuth::numeric, 1) AS azimuth,
(ARRAY['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'])
[floor((azimuth + 22.5) / 45)::int + 1] AS direction
FROM bearings
ORDER BY deg;
deg | azimuth | direction -----+---------+----------- 0 | 0.0 | N 45 | 45.0 | NE 90 | 90.0 | E 135 | 135.0 | SE 180 | 180.0 | S 225 | 225.0 | SW 270 | 270.0 | W 315 | 315.0 | NW
蓝色:原点(25,45); 绿色:目标点(75, 100); 黄色:Y轴或北; 红色:方位角。
|
蓝色:原点(75, 100); 绿色:目标点(25, 45); 黄色:Y轴或北; 红色:方位角。
|