ST_distanceWithin

更新时间:
复制 MD 格式

Returns true if the distance between two trajectory objects within the specified time range is within the reference distance.

Syntax

boolean ST_distanceWithin(trajectory traj1, trajectory traj2, tsrange range, float8 d);
boolean ST_distanceWithin(trajectory traj1, trajectory traj2, timestamp t1, timestamp t2, float8 d);

Parameters

ParameterTypeDescription
traj1, traj2trajectoryThe trajectory objects to compare.
rangetsrangeThe time range to check. Use either this parameter or t1/t2, not both.
t1timestampThe start of the time range.
t2timestampThe end of the time range.
dfloat8The reference distance.

Examples

Check whether two vehicles come within 100 meters of each other between 13:00 and 14:00:

SELECT ST_distanceWithin(
  (SELECT traj FROM traj_table WHERE id = 1),
  (SELECT traj FROM traj_table WHERE id = 2),
  '2010-1-1 13:00:00',
  '2010-1-1 14:00:00',
  100
);

Use a tsrange value to check proximity within a time window:

SELECT ST_distanceWithin(
  (SELECT traj FROM traj_table WHERE id = 1),
  (SELECT traj FROM traj_table WHERE id = 2),
  '[2010-01-01 13:00:00, 2010-01-01 14:00:00]'::tsrange,
  100
);