This topic describes the ST_Angle function. This function calculates the rotation angle of a trajectory at each intermediate point and returns an array of floating-point numbers.
Syntax
double precision[] ST_Angle(trajectory traj, boolean hasdirection default false);
Parameters
Parameter | Description |
traj | The trajectory object. |
hasdirection | Specifies whether to calculate the direction of rotation of the trajectory. |
Description
This function calculates the rotation angle of a trajectory at each intermediate point. If a trajectory has n points, the number of intermediate points of the trajectory is the difference between n and 2.
If the trajectory moves along a straight line at an intermediate point, the rotation angle of the trajectory is 0.
If the trajectory stays unchanged at an intermediate point, the rotation angle of the trajectory is NaN.
Examples
SELECT ST_Angle(ST_MakeTrajectory('STPOINT'::leaftype,'LINESTRING(0 0, 0 10, 10 10, 20 10, 30 0, 30 0, 20 10, 0 10, 0 0)', '2000-01-01', '2000-01-01'::timestamp+ '1 day'::interval* (ST_NPoints('LINESTRING(0 0, 0 10, 10 10, 20 10, 30 0, 30 0, 20 10, 0 10, 0 0)')-1), '{}'));
st_angle
-------------------------
{90,0,45,NaN,NaN,45,90}
SELECT ST_Angle(ST_MakeTrajectory('STPOINT'::leaftype,'LINESTRING(0 0, 0 10, 10 10, 20 10, 30 0, 30 0, 20 10, 0 10, 0 0)', '2000-01-01', '2000-01-01'::timestamp+ '1 day'::interval* (ST_NPoints('LINESTRING(0 0, 0 10, 10 10, 20 10, 30 0, 30 0, 20 10, 0 10, 0 0)')-1), '{}'), true);
st_angle
---------------------------
{90,0,45,NaN,NaN,-45,-90}