All Products
Search
Document Center

ApsaraDB RDS:ST_StayPoint

Last Updated:Jan 17, 2024

This topic describes the ST_StayPoint function. This function returns all stay points of a trajectory. A stay point is the point on which a moving trajectory object stays for a long period of time.

Syntax

SETOF trstaypoint ST_StayPoint(trajectory traj, interval resample_int, float dr, interval dt, float thres);
TABLE(point geometry, length interval) ST_stayPointSpatialClustered(trajectory traj, interval resample_int, float dr, interval dt, float thres, float merger)

Parameters

Parameter

Description

traj

The trajectory object.

resample_int

The interval at which the trajectory is resampled. Resampling makes the sampling points of the trajectory more even. A shorter interval indicates a more accurate stay point but a longer time period for calculation. If resampling is not required, you can set this parameter to a large value, such as '100000 day'. For more information, see ST_Resample.

dr

The tolerance that is allowed for the distance between trajectory points. The spatial tolerance is calculated based on the unit that is used for the spatial reference identifiers (SRIDs) of the trajectory. For example, if the SRID of the trajectory is 0, the spatial tolerance is calculated based on the Euclidean distance of trajectory points. If the SRID of the trajectory is 4326, the spatial tolerance is measured in the unit of meters.

dt

The tolerance that is allowed for the time difference between trajectory points. Specify a time period that is slightly longer than the time period of a single stay.

thres

If the number of sampling trajectory points around a point exceeds the value of the thres parameter, the point is considered as a stay point. If the spatial distance between a sampling trajectory point and the point is less than the value of the dr parameter and the time difference between them is less than the value of the dt parameter, the sampling trajectory point is considered be around the point. If multiple consecutive points are identified as stay points, the point that is surrounded by the most sampling points is the last stay point.

merger

If the distance between two stay points that are at different points in time is less than the value of the merger parameter, the two stay points are merged into one.

The return value is of the trstaypoint type, which is a compound type and consists of the following columns:

Column

Type

Description

point

geometry

The position of the stay point.

startt

timestamp

The time when the stay begins. The value is calculated based on the first point that is identified as the stay point.

endt

timestamp

The time when the stay ends. The value is calculated based on the last point that is identified as the stay point.

Description

This function identifies the stay points of a trajectory. For example, if you define a point that stays in the range of 500 meters for more than 30 minutes as a stay point, you can set resample_int to 5 minutes, dr to 250 meters, dt to 40 minutes, and thres to 7. The value of thres is calculated by dividing 30 by 5 and plus 1.

If a trajectory has multiple round-trip lines, you can use the ST_stayPointSpatialClustered function to aggregate spatially similar stay points and obtain the total number of stay points and total stay period of time. The stay points may indicate the places at which the moving object often stay, such as gas stations and parking lots.

Examples

SELECT ST_AsText((ST_StayPoint(traj, '12 hour', 3, '3 day', 3)).point),(ST_StayPoint(traj, '12 hour', 3, '3 day', 3)).*
FROM (SELECT ST_MakeTrajectory('STPOINT'::leaftype,'LINESTRING(1 1, 2 2, 3 3, 10 10, 11 11, 12 12, 13 13, 3 3, 2 2, 2 2, 3 3, 8 8,10 10,9 9,8 8)', '2000-01-01', '2000-01-01'::timestamp+ '1 day'::interval* (ST_NPoints('LINESTRING(1 1, 2 2, 3 3, 10 10, 11 11, 12 12, 13 13, 3 3, 2 2, 2 2, 3 3, 8 8,10 10,9 9,8 8)')-1), '{}') AS traj) tj;
 st_astext      | point                                      |   startt            | endt 
----------------+--------------------------------------------+---------------------+---------------------
 POINT(1 1)     | 0101000000000000000000F03F000000000000F03F | 2000-01-01 00:00:00 | 2000-01-03 00:00:00
 POINT(11 11)   | 010100000000000000000026400000000000002640 | 2000-01-04 00:00:00 | 2000-01-07 00:00:00
 POINT(3 3)     | 010100000000000000000008400000000000000840 | 2000-01-08 00:00:00 | 2000-01-11 00:00:00
 POINT(9.5 9.5) | 010100000000000000000023400000000000002340 | 2000-01-12 00:00:00 | 2000-01-15 00:00:00
 

SELECT ST_AsText((ST_stayPointSpatialClustered(traj, '12 hour', 3, '3 day', 3, 3)).point), (ST_stayPointSpatialClustered(traj, '12 hour', 3, '3 day', 3, 3)).*
FROM (SELECT ST_MakeTrajectory('STPOINT'::leaftype,'LINESTRING(1 1, 2 2, 3 3, 10 10, 11 11, 12 12, 13 13, 3 3, 2 2, 2 2, 3 3, 8 8,10 10,9 9,8 8)', '2000-01-01', '2000-01-01'::timestamp+ '1 day'::interval* (ST_NPoints('LINESTRING(1 1, 2 2, 3 3, 10 10, 11 11, 12 12, 13 13, 3 3, 2 2, 2 2, 3 3, 8 8,10 10,9 9,8 8)')-1), '{}') AS traj) tj;
 st_astext          | point                                      | length 
--------------------+--------------------------------------------+--------
 POINT(10.25 10.25) | 010100000000000000008024400000000000802440 | 6 days
 POINT(2 2)         | 010100000000000000000000400000000000000040 | 5 days