ST_nearestApproachPoint

更新时间:
复制 MD 格式

Returns the point on a trajectory that is closest to a specified geometry object within a given time window.

Syntax

Two signatures are available. Use the tsrange form when you have a prebuilt range value; use the t1, t2 form when you have two discrete timestamps.

geometry ST_nearestApproachPoint(trajectory traj, tsrange range, geometry g);
geometry ST_nearestApproachPoint(trajectory traj, timestamp t1, timestamp t2, geometry g);

Parameters

ParameterDescription
trajThe trajectory object to search.
rangeThe time range to search within, expressed as a tsrange value. Used in the tsrange signature only.
t1The start time of the search window. Used in the timestamp signature only.
t2The end time of the search window. Used in the timestamp signature only.
gThe specified geometry object. The function returns the point on the trajectory that is nearest to this geometry.

Example

The following query finds the point on each trajectory in traj_table that is closest to the line LINESTRING(0 0, 5 5, 9 9), considering only trajectory positions recorded between 13:00 and 14:00 on January 1, 2010. The result is a geometry point value.

-- Find the nearest approach point to a diagonal line within a one-hour window
SELECT ST_nearestApproachPoint(
    traj,
    '2010-1-1 13:00:00',
    '2010-1-1 14:00:00',
    'LINESTRING(0 0, 5 5, 9 9)'::geometry
)
FROM traj_table;
-- Returns: a geometry point per row representing the closest position on that
-- trajectory to the specified line within the time window