Returns true if the time difference between two trajectory objects at any shared spatial point within the specified time range is within the reference interval.
Syntax
boolean ST_durationWithin(trajectory traj1, trajectory traj2, tsrange range, interval i);
boolean ST_durationWithin(trajectory traj1, trajectory traj2, timestamp t1, timestamp t2, interval i);Two overloads are available: one accepts a tsrange value, the other accepts explicit timestamp start and end times.
Parameters
| Parameter | Description |
|---|---|
traj | The trajectory object. Applies to both traj1 and traj2. |
range | The time range, as a tsrange value. |
t1 | The start time. |
t2 | The end time. |
i | The reference interval. |
Description
ST_durationWithin checks whether two trajectory objects were at the same spatial point within a given time range and, if so, whether their arrival times differed by no more than the reference interval.
If traj1 and traj2 intersect at the same spatial point multiple times within the time range, the function returns true as long as any single intersection satisfies the interval condition.
Examples
The following example uses the timestamp-based overload to check whether two trajectories in traj_table were at the same spatial point between 13:00 and 14:00 on January 1, 2010, with a time difference of 30 seconds or less.
SELECT ST_durationWithin(
(SELECT traj FROM traj_table WHERE id = 1),
(SELECT traj FROM traj_table WHERE id = 2),
'2010-1-1 13:00:00',
'2010-1-1 14:00:00',
INTERVAL '30s'
);