ST_nearestApproachDistance

更新时间:
复制 MD 格式

Returns the minimum distance between a trajectory object and a geometry object within a specified time range. The return type is float8.

Syntax

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

Two overloads are available: one accepts a tsrange value, the other accepts explicit start and end timestamps.

Parameters

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

Example

The following query returns the minimum distance between each trajectory in traj_table and a line segment over a one-hour window.

-- Find the nearest approach distance between each trajectory and a line, from 13:00 to 14:00
SELECT ST_nearestApproachDistance(
  traj,
  '2010-01-01 13:00:00',
  '2010-01-01 14:00:00',
  'LINESTRING(0 0, 5 5, 9 9)'::geometry
) AS nearest_distance
FROM traj_table;