ST_Azimuth — Renvoie l'azimut basé sur le nord d'une ligne entre deux points.
float ST_Azimuth(geometry origin, geometry target);
float ST_Azimuth(geography origin, geography target);
Renvoie l'azimut en radians du point cible par rapport au point d'origine, ou NULL si les deux points coïncident. L'angle d'azimut est un angle positif dans le sens des aiguilles d'une montre, référencé à partir de l'axe Y positif (geometry) ou du méridien Nord (geography) : North = 0; Northeast = π/4; East = π/2; Southeast = 3π/4; South = π; Southwest 5π/4; West = 3π/2; Northwest = 7π/4.
Pour le type geography, la solution azimutale est connue sous le nom de inverse geodesic problem.
L'azimut est un concept mathématique défini comme l'angle entre un vecteur de référence et un point, avec des unités angulaires en radians. La valeur du résultat en radians peut être convertie en degrés à l'aide de la fonction PostgreSQL degrees().
For offsetting lines relative to their direction, use ST_OffsetCurve. For projecting a point by distance and bearing, use ST_Project.
Disponibilité : 1.1.0
Amélioration : la prise en charge du type geography a été introduite dans la version 2.0.0.
Amélioration : 2.2.0 mesure sur sphéroïde effectuée avec GeographicLib pour améliorer la précision et la robustesse. Nécessite PROJ >= 4.9.0 pour profiter de la nouvelle fonctionnalité.
Geometry Azimut en degrés
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
Azimuth from Point(25, 45) to Point(75, 100), shown against the positive Y axis (north).
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)
Reverse azimuth from Point(75, 100) to Point(25, 45).
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)
ST_Angle, ST_Point, ST_Translate, ST_Project, PostgreSQL Math Functions