All Products
Search
Document Center

PolarDB:ST_Angle

Last Updated:Mar 28, 2026

Calculates the rotation angle of a trajectory at each intermediate point and returns the results as an array of double precision values.

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 return negative values. Default value: false.

Description

For a trajectory with *n* points, ST_Angle evaluates each of the *n* − 2 intermediate points and returns the rotation angle at that point.

  • If the trajectory moves in a straight line at an intermediate point, the rotation angle is 0.

  • If the trajectory does not move at an intermediate point, the rotation angle is NaN.

Examples

The following examples use the same nine-point LINESTRING. The trajectory has 7 intermediate points, so ST_Angle returns an array of 7 values.

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)'));
        st_angle
-------------------------
 {90,0,45,NaN,NaN,45,90}
(1 row)

With direction

Setting hasdirection to true returns negative values for counterclockwise rotations.

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);
         st_angle
---------------------------
 {90,0,45,NaN,NaN,-45,-90}
(1 row)