Returns true if two trajectory objects intersect at the same spatial point within a specified time range and the difference between their intersection timestamps falls 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);Parameters
| Parameter | Description |
|---|---|
traj1, traj2 | The trajectory objects to compare. |
range | The time range to search for intersections, specified as a tsrange value. |
t1 | The start of the time range. |
t2 | The end of the time range. |
i | The reference interval. The function returns true if the difference between the intersection timestamps of the two trajectories is within this interval. |
Usage notes
If the two trajectories intersect at the same spatial point more than once within the specified time range, the function returns
trueas long as any one of those intersections has a timestamp difference within the reference interval.The two overloads are equivalent. Use
tsrangewhen the time range is already stored as a range type; uset1andt2when you have discrete timestamp values.
Example
Check whether two trajectories intersect at the same spatial point between 13:00 and 14:00 on January 1, 2010, and whether their timestamp difference at any such intersection is within 30 seconds:
SELECT ST_durationWithin(
(SELECT traj FROM traj_table WHERE id = 1),
(SELECT traj FROM traj_table WHERE id = 2),
'2010-01-01 13:00:00',
'2010-01-01 14:00:00',
INTERVAL '30s'
);