Returns the portions of a trajectory that intersect a geometry object within a specified time range, as an array of sub-trajectories.
Syntax
trajectory[] ST_intersection(trajectory traj, tsrange range, geometry g);
trajectory[] ST_intersection(trajectory traj, timestamp t1, timestamp t2, geometry g);The two overloads differ only in how you specify the time range: use a tsrange value or two timestamp bounds (t1, t2).
Parameters
| Parameter | Type | Description |
|---|---|---|
traj | trajectory | The trajectory object to evaluate. |
range | tsrange | The time range. Used in the first overload. |
t1 | timestamp | The start of the time range. Used in the second overload. |
t2 | timestamp | The end of the time range. Used in the second overload. |
g | geometry | The geometry object to intersect against. |
Description
ST_intersection clips a trajectory to the parts that fall within both the specified time range and the spatial boundary of the geometry object.
If the trajectory crosses the geometry at multiple separate locations, the function returns multiple sub-trajectories — one for each continuous intersection segment.
Examples
Basic usage — intersect a trajectory with a line segment
SELECT ST_intersection(
traj,
'2010-1-1 13:00:00',
'2010-1-1 14:00:00',
'LINESTRING(0 0, 5 5, 9 9)'::geometry
)
FROM traj_table;