제목

ST_Azimuth — 두 도형 사이의 2차원 최단 라인을 반환합니다.

요약

float ST_Azimuth(geometry origin, geometry target);

float ST_Azimuth(geography origin, geography target);

설명

Returns the azimuth in radians of the target point from the origin point, or NULL if the two points are coincident. The azimuth angle is a positive clockwise angle referenced from the positive Y axis (geometry) or the North meridian (geography): North = 0; Northeast = π/4; East = π/2; Southeast = 3π/4; South = π; Southwest 5π/4; West = 3π/2; Northwest = 7π/4.

For the geography type, the azimuth solution is known as the inverse geodesic problem.

The azimuth is a mathematical concept defined as the angle between a reference vector and a point, with angular units in radians. The result value in radians can be converted to degrees using the PostgreSQL function 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 이상 버전이 필요합니다.

예시

도 단위의 도형 방위각

Code
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.

Code
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

Azimuth from Point(25, 45) to Point(75, 100), shown against the positive Y axis (north).

Code
WITH points AS (
  SELECT 'POINT(25 45)'::geometry AS origin,
         'POINT(75 100)'::geometry AS target
)
SELECT round(degrees(ST_Azimuth(origin, target))::numeric, 6) AS degrees,
       ST_MakeLine(origin, ST_Translate(origin, 0, 105)) AS north,
       ST_MakeLine(origin, target) AS direction
FROM points;
래스터 출력
42.273689 | LINESTRING(25 45,25 150) | LINESTRING(25 45,75 100)
Figure
Geometry figure for visual-st-azimuth-03

Reverse azimuth from Point(75, 100) to Point(25, 45).

Code
WITH points AS (
  SELECT 'POINT(75 100)'::geometry AS origin,
         'POINT(25 45)'::geometry AS target
)
SELECT round(degrees(ST_Azimuth(origin, target))::numeric, 6) AS degrees,
       ST_MakeLine(origin, ST_Translate(origin, 0, 90)) AS north,
       ST_MakeLine(origin, target) AS direction
FROM points;
래스터 출력
222.273689 | LINESTRING(75 100,75 190) | LINESTRING(75 100,25 45)
Figure
Geometry figure for visual-st-azimuth-04