ST_samplingInterval

更新时间:
复制 MD 格式

Returns the time elapsed between consecutive sampling points in a trajectory.

Syntax

interval ST_samplingInterval(trajectory traj);

Parameters

ParameterDescription
trajThe trajectory object.

Returns

Returns a PostgreSQL interval value representing the time between two adjacent sampling points. For example, @ 20 mins means the interval is 20 minutes.

Examples

The following example constructs a trajectory with three sampling points over a one-hour period and retrieves the sampling interval.

WITH traj AS (
  SELECT ST_MakeTrajectory(
    'STPOINT'::leaftype,
    st_geomfromtext('LINESTRING (114 35, 115 36, 116 37)', 4326),
    '[2010-01-01 14:30, 2010-01-01 15:30)'::tsrange,
    '{"leafcount":3,"attributes":{"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120,130,140]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120,130,140]},"acceleration":{"type":"string","length":20,"nullable":true,"value":["120","130","140"]},"active":{"type":"timestamp","nullable":false,"value":["Fri Jan 01 14:30:00 2010","Fri Jan 01 15:00:00 2010","Fri Jan 01 15:30:00 2010"]}},"events":[{"1":"Fri Jan 01 14:30:00 2010"},{"2":"Fri Jan 01 15:00:00 2010"},{"3":"Fri Jan 01 15:30:00 2010"}]}'
  ) AS t
)
SELECT ST_samplingInterval(t) FROM traj;

Output:

 st_samplinginterval
---------------------
 @ 20 mins
(1 row)

The trajectory spans 60 minutes across 3 points, so the interval between consecutive points is 20 minutes.

Related functions

  • ST_MakeTrajectory: Build a trajectory object from geometry, time range, and attributes.

  • ST_leafCount: Get the number of sampling points in a trajectory.

  • ST_duration: Get the total time span of a trajectory.