Returns the count of neighboring sampling points for each point in a trajectory, based on a spatial range and a time range.
Syntax
integer[] ST_Density(trajectory traj, float dr, interval dt);Parameters
| Parameter | Type | Description |
|---|---|---|
traj | trajectory | The trajectory to analyze. |
dr | float | The spatial range of the neighborhood. The unit depends on the spatial reference identifier (SRID) of the trajectory. |
dt | interval | The time range of the neighborhood. |
dr and dt together define the neighborhood boundary. A sampling point falls within the neighborhood of a trajectory point only when both conditions are satisfied simultaneously.
How it works
For each trajectory point, ST_Density counts all sampling points that satisfy both of the following conditions (including the point itself):
The spatial distance between the sampling point and the trajectory point is less than
dr, calculated based on the trajectory's SRID.The time difference between them is less than
dt.
The function returns one integer per trajectory point. Each integer represents the number of sampling points in that point's neighborhood.
Example
SELECT ST_Density(
ST_makeTrajectory(
'STPOINT'::leaftype,
ARRAY[1::float8, 2, 3, 4, 5],
ARRAY[2::float8, 10, 9, 8, 7],
4326,
ARRAY[
'2010-01-01 11:30'::timestamp,
'2010-01-01 11:31',
'2010-01-01 11:32',
'2010-01-01 11:33',
'2010-01-01 11:34'
]
),
400000,
'10 minute'
);Output:
st_density
-------------
{1,3,4,4,3}
(1 row)The trajectory has 5 points with SRID 4326. With a spatial range of 400000 and a time range of 10 minute, the result {1,3,4,4,3} means:
Point 1 has 1 sampling point in its neighborhood (itself only).
Point 2 has 3 sampling points in its neighborhood.
Point 3 has 4 sampling points in its neighborhood.
Point 4 has 4 sampling points in its neighborhood.
Point 5 has 3 sampling points in its neighborhood.