名称

ST_DistanceCPA — 返回两个轨迹的最近接近点的距离。

语法

float8 ST_DistanceCPA(geometry track1, geometry track2);

描述

返回两个移动对象之间的最小距离。

输入必须是 ST_IsValidTrajectory 检查过的有效轨迹。如果轨迹在 M 范围内不重叠,则返回 Null。

可用性:2.2.0

此函数支持 3d,并且不会删除 z 索引。

示例

-- Return the minimum distance of two objects moving between 10:00 and 11:00
WITH inp AS ( SELECT
  ST_AddMeasure('LINESTRING Z (0 0 0, 10 0 5)'::geometry,
    extract(epoch from '2015-05-26 10:00'::timestamptz),
    extract(epoch from '2015-05-26 11:00'::timestamptz)
  ) a,
  ST_AddMeasure('LINESTRING Z (0 2 10, 12 1 2)'::geometry,
    extract(epoch from '2015-05-26 10:00'::timestamptz),
    extract(epoch from '2015-05-26 11:00'::timestamptz)
  ) b
)
SELECT ST_DistanceCPA(a,b) distance FROM inp;

     distance
------------------
 1.96036833151395

另请参阅

ST_IsValidTrajectoryST_ClosestPointOfApproachST_AddMeasure|=|