Returns the trajectory sampling points where a trajectory crosses the boundary of a geometric area — that is, points where the trajectory transitions from outside to inside the area, or from inside to outside.
Syntax
TABLE(idx integer, inside bool, pnt trajectory, t timestamp, x double precision, y double precision) ST_CrossingPoints(trajectory traj, geometry geom)Parameters
| Parameter | Description |
|---|---|
| traj | The trajectory object. |
| geom | The geometric area. |
Return values
Returns a table with one row per crossing point.
| Column | Type | Description |
|---|---|---|
| idx | integer | The index of the trajectory sampling point, starting from 0. |
| inside | bool | Specifies whether the crossing point is entering the geometric area (true) or leaving it (false). |
| pnt | trajectory | The crossing point, represented as a single-point trajectory that includes attribute information. |
| t | timestamp | The timestamp of the crossing point. |
| x | double precision | The x-coordinate of the crossing point. |
| y | double precision | The y-coordinate of the crossing point. |
Description
A sampling point is a crossing point if the preceding sampling point and the following sampling point are on opposite sides of the geometric area boundary — one inside and one outside. Each crossing point is returned as a separate row.
Example
Query the crossing points of a trajectory that enters and exits 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:
idx=3 (
inside=t): The trajectory enters the polygon at point (3, 3) on 2000-01-04.idx=4 (
inside=f): The trajectory exits the polygon at point (0, 0) on 2000-01-05.