ST_DistanceCPA — Returns the distance between the closest point of approach of two trajectories.
float8 ST_DistanceCPA(
geometry track1, geometry track2)
;
Returns the distance (in 2D) between two trajectories at their closest point of approach.
Inputs must be valid trajectories as checked by ST_IsValidTrajectory. Null is returned if the trajectories do not overlap in their M ranges.
Availability: 2.2.0
This function supports 3d and will not drop the z-index.
-- 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