ST_CPAWithin
Name
ST_CPAWithin — Tests if the closest point of approach of two trajectories is within the specified distance.
Synopsis
boolean
ST_CPAWithin
(
geometry
track1
, geometry
track2
, float8
dist
)
;
Description
Tests whether two moving objects have ever been closer than the specified distance.
Inputs must be valid trajectories as checked by ST_IsValidTrajectory . False 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.
Examples
WITH inp AS ( SELECT
ST_AddMeasure('LINESTRING Z (0 0 0,10 0 5)'::geometry,
extract(epoch from timestamp '2015-05-26 10:00' AT TIME ZONE 'UTC'),
extract(epoch from timestamp '2015-05-26 11:00' AT TIME ZONE 'UTC')
) a,
ST_AddMeasure('LINESTRING Z (0 2 10,12 1 2)'::geometry,
extract(epoch from timestamp '2015-05-26 10:00' AT TIME ZONE 'UTC'),
extract(epoch from timestamp '2015-05-26 11:00' AT TIME ZONE 'UTC')
) b
)
SELECT ST_CPAWithin(a, b, 2), ST_DistanceCPA(a, b) distance FROM inp;
st_cpawithin | distance --------------+------------------ t | 1.9652147377620688
See Also
ST_IsValidTrajectory , ST_ClosestPointOfApproach , ST_DistanceCPA , |=|