Returns the portion of a trajectory object—within a specified time range—that falls outside a given geometry object.
Syntax
trajectory ST_difference(trajectory traj, tsrange range, geometry g);
trajectory ST_difference(trajectory traj, timestamp t1, timestamp t2, geometry g);Two overloads are available: one accepts a tsrange for the time range, the other accepts discrete timestamp values for the start and end times.
Parameters
| Parameter | Type | Description |
|---|---|---|
traj | trajectory | The source trajectory object. |
range | tsrange | The time range. Used in the first overload. |
t1 | timestamp | The start time. Used in the second overload. |
t2 | timestamp | The end time. Used in the second overload. |
g | geometry | The specified geometry object. |
Examples
Use discrete timestamps
The following example computes the difference between a trajectory between 13:00 and 14:00 and a line geometry. The returned trajectory contains only the trajectory segments that lie outside the LINESTRING.
SELECT ST_difference(traj, '2010-1-1 13:00:00', '2010-1-1 14:00:00', 'LINESTRING(0 0, 5 5, 9 9)'::geometry)
FROM traj_table;