All Products
Search
Document Center

PolarDB:ST_Angle

Last Updated:Mar 28, 2026

ST_Angle calculates the rotation angle at each intermediate point of a trajectory and returns the results as an array of floating-point numbers.

Syntax

double precision[] ST_Angle(trajectory traj, boolean hasdirection default false);

Parameters

ParameterDescription
trajThe trajectory object.
hasdirectionSpecifies whether to include rotation direction in the result. When set to true, counterclockwise rotations are returned as negative values. Defaults to false.

Description

For a trajectory with n points, ST_Angle computes the rotation angle at each of the n − 2 intermediate points (all points except the first and last).

Two special cases apply at an intermediate point:

  • If the trajectory moves in a straight line, the rotation angle is 0.

  • If the trajectory does not move (the point is stationary), the rotation angle is NaN.

Examples

Without direction (default)

SELECT ST_Angle(ST_MakeTrajectory('LINESTRING(0 0, 0 10, 10 10, 20 10, 30 0, 30 0, 20 10, 0 10, 0 0)'));

Output:

        st_angle
-------------------------
 {90,0,45,NaN,NaN,45,90}
(1 row)

The trajectory has 9 points, so ST_Angle returns 7 values — one for each intermediate point. The two NaN values correspond to the stationary point at (30 0, 30 0).

With direction (counterclockwise returns negative)

SELECT ST_Angle(ST_MakeTrajectory('LINESTRING(0 0, 0 10, 10 10, 20 10, 30 0, 30 0, 20 10, 0 10, 0 0)'), true);

Output:

         st_angle
---------------------------
 {90,0,45,NaN,NaN,-45,-90}
(1 row)

With hasdirection set to true, counterclockwise rotations are returned as negative values. The last two angles change from 45 and 90 to -45 and -90, reflecting that the trajectory turns counterclockwise on the return path.