ST_CrossingPoints

更新时间:
复制 MD 格式

Returns each sampling point where a trajectory crosses the boundary of a geometric area, either entering or leaving it.

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 to test against.

Return values

Each crossing point is returned as a separate row.

ColumnTypeDescription
idxintegerThe sequence number of the sampling point, starting from 0.
insideboolIndicates whether the point is inside the geometric area.
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.

How it works

A sampling point is a crossing point when the trajectory transitions across the boundary of the geometric area:

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

  • The previous sampling point is inside the area and the next sampling point is outside — the trajectory leaves the area.

Example

Find all crossing points of a trajectory that enters and then exits a polygon area.

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))'
);

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 trajectory has 7 sampling points (indices 0–6). Point 3 (inside=t) is at coordinates (3, 3) on 2000-01-04. Point 4 (inside=f) is at coordinates (0, 0) on 2000-01-05.