ST_FINAL_BEARING

Compute the final bearing in compass degrees at the destination of a great-circle path from one point to another.

Category: geospatialReturns: DOUBLEDialect: Standard

Syntax

ST_FINAL_BEARING(lat1, lng1, lat2, lng2)

Description

## Overview Returns the final bearing at the destination of a great-circle path, measured clockwise from true north. The result is in compass degrees in the range [0, 360). This is the heading you would observe at the destination if you were travelling along a great-circle route from the starting point. Great-circle paths curve across the Earth's surface, so the bearing at the destination is generally different from the initial bearing at the origin. On short paths (a few hundred kilometers) the two bearings are nearly equal; on intercontinental paths they can differ by tens of degrees. ## When to use ST_FINAL_BEARING vs. alternatives - **ST_FINAL_BEARING** (this function): bearing at the destination, in compass degrees. Use for arrival-heading analysis, runway assignment, docking approach, and any question about the orientation at the endpoint of a route. - **ST_BEARING**: bearing at the origin, in compass degrees. Use for departure-heading queries. - **ST_AZIMUTH**: bearing at the origin, in radians. Use when chaining with other trigonometric SQL functions. - **Waypoint bearing**: if you need the bearing at an intermediate point, call ST_BEARING from that waypoint rather than interpolating between the initial and final bearings. ## Behavior - The result is in compass degrees in [0, 360). Multiply by PI/180 for radians. - Uses a spherical Earth model with mean radius 6,371,008.8 meters, matching ST_BEARING. - Internally computed as the reverse initial bearing from the destination back to the origin, offset by 180 and normalized into [0, 360). - Arguments are ordered (lat, lng), not (lng, lat). - Returns NULL if any argument is NULL. - Returns 0 when the two points are identical because the bearing is undefined. - Handles the antimeridian correctly; no pre-normalization of longitudes is required. - Near the poles the formula is numerically sensitive to small coordinate changes. ## Accuracy and performance - Spherical accuracy matches ST_BEARING. For geodetic surveying use an ellipsoidal alternative. - Performance is constant cost per call; comparable to ST_BEARING and ST_DISTANCE_HAVERSINE. - The bearing changes continuously along the great-circle path. Sampling at intermediate waypoints requires calling the function (or ST_BEARING) at each waypoint rather than interpolating. ## Compatibility - Matches the final-bearing convention used by standard great-circle navigation libraries. - Output range [0, 360) is normalized for direct comparison with compass-degree thresholds.

Parameters

NameTypeDescription
lat1Specifies the WGS 84 latitude of the starting point in decimal degrees, in the range -90 to 90.
lng1Specifies the WGS 84 longitude of the starting point in decimal degrees, in the range -180 to 180.
lat2Specifies the WGS 84 latitude of the destination point in decimal degrees, in the range -90 to 90.
lng2Specifies the WGS 84 longitude of the destination point in decimal degrees, in the range -180 to 180.

Examples

-- Compass degrees, measured clockwise from true north, as seen at the destination.
SELECT ST_FINAL_BEARING(51.5074, -0.1278, 48.8566, 2.3522) AS final_bearing_deg;
-- The two bearings differ noticeably on long great-circle paths.
SELECT
  ST_BEARING(51.5074, -0.1278, 40.7128, -74.0060) AS initial_deg,
  ST_FINAL_BEARING(51.5074, -0.1278, 40.7128, -74.0060) AS final_deg,
  ST_FINAL_BEARING(51.5074, -0.1278, 40.7128, -74.0060) -
    ST_BEARING(51.5074, -0.1278, 40.7128, -74.0060) AS delta_deg;
-- Pair with distance for a complete route summary.
SELECT flight_id,
       ST_DISTANCE_HAVERSINE(o_lat, o_lng, d_lat, d_lng) AS distance_m,
       ST_BEARING(o_lat, o_lng, d_lat, d_lng) AS initial_bearing_deg,
       ST_FINAL_BEARING(o_lat, o_lng, d_lat, d_lng) AS final_bearing_deg
FROM aviation.catalog.flights;
-- Keep flights whose arrival heading is roughly north (final bearing within 15 degrees of 0).
SELECT flight_id
FROM aviation.catalog.flights
WHERE ABS(ST_FINAL_BEARING(o_lat, o_lng, d_lat, d_lng)) < 15.0
   OR ST_FINAL_BEARING(o_lat, o_lng, d_lat, d_lng) > 345.0;
-- On short paths the two bearings differ by under a degree.
SELECT
  ST_BEARING(48.8584, 2.2945, 48.8606, 2.3376) AS initial_deg,
  ST_FINAL_BEARING(48.8584, 2.2945, 48.8606, 2.3376) AS final_deg;
-- Any NULL input yields NULL.
SELECT ST_FINAL_BEARING(51.5074, -0.1278, NULL, 2.3522) AS bearing;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →