All Products
Search
Document Center

ApsaraDB RDS:ST_CrossingPoints

Last Updated:Mar 27, 2026

Returns the sampling points at which a trajectory crosses the boundary of a geometric area.

Syntax

TABLE(idx integer, inside bool, pnt trajectory, t timestamp, x double precision, y double precision) ST_CrossingPoints(trajectory traj, geometry geom)

Parameters

ParameterDescription
trajThe trajectory object.
geomThe geometric area.

Return values

Returns a table where each row represents one crossing point.

ColumnTypeDescription
idxintegerThe sequence number of the sampling point in the trajectory, starting from 0.
insideboolSpecifies whether the crossing point enters the geometric area (true) or exits it (false).
pnttrajectoryThe crossing point as a single-point trajectory, including attribute information.
ttimestampThe timestamp of the crossing point.
xdouble precisionThe x-coordinate of the crossing point.
ydouble precisionThe y-coordinate of the crossing point.

Description

A crossing point is a sampling point where the trajectory transitions between inside and outside the geometric area:

  • The previous sampling point is outside the area and the current point is inside — the trajectory enters the area.

  • The previous sampling point is inside the area and the current point is outside — the trajectory exits the area.

Each crossing point is returned as a separate row.

Example

Query the crossing points of a trajectory that moves into and then out of a polygon.

SELECT * FROM ST_CrossingPoints(
               '{"trajectory":{"version":1,"type":"STPOINT","leafcount":7,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-07 00:00:00","spatial":"LINESTRING(0 0,2 1,0 0,3 3,0 0,1 4,0 0)","timeline":["2000-01-01 00:00:00","2000-01-02 00:00:00","2000-01-03 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00","2000-01-06 00:00:00","2000-01-07 00:00:00"]}}',
               'POLYGON((2 2, 2 3, 3 3, 3 2, 2 2))');

Sample result:

 idx | inside |                                                                                            pnt                                                                                            |          t          | x | y
-----+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------+---+---
   3 | t      | {"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2000-01-04 00:00:00","end_time":"2000-01-04 00:00:00","spatial":"POINT(3 3)","timeline":["2000-01-04 00:00:00"]}} | 2000-01-04 00:00:00 | 3 | 3
   4 | f      | {"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2000-01-05 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"POINT(0 0)","timeline":["2000-01-05 00:00:00"]}} | 2000-01-05 00:00:00 | 0 | 0
(2 rows)

The result shows two crossing points: sampling point 3 (idx=3) where the trajectory enters the polygon at (3, 3), and sampling point 4 (idx=4) where it exits at (0, 0).