All Products
Search
Document Center

ApsaraDB RDS:ST_removeDriftPoints

Last Updated:Mar 28, 2026

Removes drift points from a trajectory object based on combined speed, distance, and time thresholds. A trajectory point is deleted only when all three conditions are met simultaneously.

Syntax

trajectory ST_removeDriftPoints(trajectory traj, float8 speed, float8 dist, interval offset);

Parameters

ParameterTypeDescription
trajtrajectoryThe source trajectory object.
speedfloat8The speed threshold, in meters per second. Calculated in real time based on the trajectory point's position and time offset.
distfloat8The distance threshold, in meters. Measured as the spherical distance from the current point to the previous point.
offsetintervalThe time interval threshold. Use PostgreSQL interval syntax, for example, interval '30 seconds' or interval '1 minute'.

A trajectory point is removed when its speed exceeds speed, its distance from the previous point exceeds dist, and its time interval exceeds offset. Points that satisfy only one or two conditions are retained.

Return value

Returns the updated trajectory object. The returned object always contains at least two trajectory points. If the input trajectory has exactly two points, no points are removed.

Usage notes

Coordinate reference system (CRS): By default, trajectory objects use World Geodetic System 1984 (WGS 84). To use a different CRS, specify a spatial reference system identifier (SRID) when creating the trajectory object, or call ST_SetSRID to set it later. Spherical distances are calculated based on the configured SRID and expressed in meters.

Example

This example removes drift points from a trajectory with 53 points, using a speed threshold of 25.72 m/s (approximately 92.6 km/h), a distance threshold of 9,620 m, and a time threshold of 30 seconds. Two points meet all three conditions and are removed, leaving 49 points.

-- Check the initial point count
SELECT id, st_leafcount(traj) FROM table_name WHERE id = 1;
 id | st_leafcount
----+--------------
  1 |           53
(1 row)

-- Remove drift points: speed > 25.72 m/s (~92.6 km/h), distance > 9,620 m, time interval > 30 seconds
UPDATE table_name SET traj = ST_removeDriftPoints(traj, 25.72, 9620, interval '30 seconds') WHERE id = 1;

-- Two drift points removed. New count: 49
SELECT id, st_leafcount(traj) FROM table_name WHERE id = 1;
 id | st_leafcount
----+--------------
  1 |           49
(1 row)