All Products
Search
Document Center

PolarDB:ST_{Z|T|2D|2DT|3D|3DT}Intersects

Last Updated:Mar 28, 2026

Returns true if two spatial objects intersect in the specified dimensions — that is, if their intersection in those dimensions is non-empty (A ∩ B ≠ ∅).

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

ParameterDescription
geomThe geometry to compare.
trajThe trajectory to compare, or the original trajectory that includes the sub-trajectory to compare.
traj1The trajectory to compare, or the original trajectory that includes the sub-trajectory to compare.
traj2The trajectory to compare, or the original trajectory that includes the sub-trajectory to compare.
boxThe bounding box to compare.
tsThe start of the time range for extracting sub-trajectories. Optional.
teThe end of the time range for extracting sub-trajectories. Optional.

Description

Each function variant checks for intersection in specific dimensions. When a dimension is not constrained by the function name, it is treated as unconstrained — any value in that dimension is accepted.

Effect of `ts` and `te`: When ts and te are provided, the function extracts sub-trajectories over that time range before comparing. Without ts and te, the function compares the complete trajectories. The two objects being compared are specified by the traj or traj1 parameter and the traj2 parameter.

Why 2D and 2DT can return different results: ST_2DIntersects checks only the X and Y axes, so two trajectories that cross in space are considered intersecting even if they were at those locations at different times. ST_2DTIntersects additionally requires the objects to overlap in the time dimension, so the same two trajectories may not intersect if they never occupied the same location at the same time.

Equivalence with `ST_Intersects`:

  • ST_Intersects(...) behaves as ST_2DIntersects(...) when one of the objects is a geometry.

  • ST_Intersects(...) behaves as ST_3DTIntersects(...) when both objects are trajectory values.

Example

The following query compares two trajectories across four dimension combinations.

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

The two trajectories cross in 2D space (st_2dintersects = t), but they never occupy the same location at the same time (st_2dtintersects = f). The 3D variants produce the same pattern because the Z coordinate is 0 for all points in both trajectories, so adding the Z axis does not change whether the paths cross.