All Products
Search
Document Center

PolarDB:ST_nearestApproachDistance

Last Updated:Mar 28, 2026

Returns the minimum distance between a trajectory object and a geometry object within a specified time range.

Syntax

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

Parameters

ParameterTypeDescription
trajtrajectoryThe trajectory object.
rangetsrangeThe time range.
t1timestampThe start of the time range.
t2timestampThe end of the time range.
ggeometryThe geometry object to measure distance to.

Example

The following example returns the minimum distance between the trajectory in each row and a line segment, evaluated over a one-hour window.

SELECT ST_nearestApproachDistance(
    traj,
    '2010-1-1 13:00:00',
    '2010-1-1 14:00:00',
    'LINESTRING(0 0, 5 5, 9 9)'::geometry
)
FROM traj_table;