All Products
Search
Document Center

PolarDB:ST_intersection

Last Updated:Mar 28, 2026

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

ParameterTypeDescription
trajtrajectoryThe trajectory object to evaluate.
rangetsrangeThe time range. Used in the first overload.
t1timestampThe start of the time range. Used in the second overload.
t2timestampThe end of the time range. Used in the second overload.
ggeometryThe 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;