Checks whether two spatial objects share at least one point in the specified dimension(s). Returns true if they intersect; returns false otherwise.
Syntax
bool ST_{2D|3D}Intersects(geometry geom, trajectory traj);
bool ST_{2D|3D}Intersects(trajectory traj, geometry geom);
bool ST_{2D|3D}Intersects(geometry geom, trajectory traj, timestamp ts, timestamp te);
bool ST_{2D|3D}Intersects(trajectory traj, geometry geom, timestamp ts, timestamp te);
bool ST_{Z|T|2D|2DT|3D|3DT}Intersects(boxndf box, trajectory traj);
bool ST_{Z|T|2D|2DT|3D|3DT}Intersects(trajectory traj, boxndf box);
bool ST_{Z|T|2D|2DT|3D|3DT}Intersects(boxndf box, trajectory traj, timestamp ts, timestamp te);
bool ST_{Z|T|2D|2DT|3D|3DT}Intersects(trajectory traj, boxndf box, timestamp ts, timestamp te);
bool ST_{2D|2DT|3D|3DT}Intersects(trajectory traj1, trajectory traj2);
bool ST_{2D|2DT|3D|3DT}Intersects(trajectory traj1, trajectory traj2, timestamp ts, timestamp te);Parameters
| Parameter | Type | Description |
|---|---|---|
geom | geometry | The geometry to compare. |
traj | trajectory | The trajectory to compare, or the original trajectory that contains the sub-trajectory to compare. |
traj1 | trajectory | The trajectory to compare, or the original trajectory that contains the sub-trajectory to compare. |
traj2 | trajectory | The trajectory to compare, or the original trajectory that contains the sub-trajectory to compare. |
box | boxndf | The bounding box to compare. |
ts | timestamp | The start of the time range used to extract a sub-trajectory. Optional. |
te | timestamp | The end of the time range used to extract a sub-trajectory. Optional. |
Description
The function suffix controls which dimensions the intersection check covers:
| Suffix | Dimensions checked |
|---|---|
2D | X and Y axes |
3D | X, Y, and Z axes |
T | Time dimension only |
Z | Z axis only |
2DT | X, Y, and time |
3DT | X, Y, Z, and time |
For any dimension not covered by the suffix, the function treats that dimension as unconstrained — any value qualifies.
Complete trajectories vs. sub-trajectories:
Without
tsandte: compares the full trajectories of both objects.With
tsandte: extracts sub-trajectories over the specified time range, then compares those sub-trajectories.
`ST_Intersects` alias behavior:
ST_Intersects(...) is equivalent to:
ST_2DIntersects(...)when one of the objects is a geometryST_3DTIntersects(...)when both objects are trajectories
Example
The following example checks four intersection variants between two trajectories: ST_2dIntersects, ST_2dtIntersects, ST_3dIntersects, and ST_3dtIntersects. The two trajectories share spatial extent in 2D and 3D but have non-overlapping time ranges, so only the spatial-only checks return t.
WITH traj AS (
SELECT (
'{"trajectory":{"version":1,"type":"STPOINT","leafcount":6,"start_time":"2000-01-01 03:15:42","end_time":"2000-01-01 05:16:43",' ||
'"spatial":"LINESTRING(2 2 0,33.042158099636 36.832684322819 0,47.244002354518 47.230026333034 0,64.978971942887 60.618813472986 0,77.621717839502 78.012496630661 0,80 78 0)",' ||
'"timeline":["2000-01-01 03:15:42","2000-01-01 03:39:54","2000-01-01 04:04:06","2000-01-01 04:28:18","2000-01-01 04:52:31","2000-01-01 05:16:43"]}}'
)::trajectory a,
(
'{"trajectory":{"version":1,"type":"STPOINT","leafcount":4,"start_time":"2000-01-01 02:17:58.656079","end_time":"2000-01-01 03:43:59.620923",' ||
'"spatial":"LINESTRING(40 2 0,15.17549143297 51.766017656152 0,1.444002354518 69.630026333034 0,3 70 0)",' ||
'"timeline":["2000-01-01 02:17:58.656079","2000-01-01 02:46:38.977693","2000-01-01 03:15:19.299307","2000-01-01 03:43:59.620923"]}}'
)::trajectory b
)
SELECT ST_2dIntersects(a, b), ST_2dtIntersects(a, b), ST_3dIntersects(a, b), ST_3dtIntersects(a, b)
FROM traj;Output:
st_2dintersects | st_2dtintersects | st_3dintersects | st_3dtintersects
-----------------+------------------+-----------------+------------------
t | f | t | f