All Products
Search
Document Center

PolarDB:ST_Resample

Last Updated:Mar 28, 2026

Resamples a trajectory by adding or removing points based on a distance or time threshold.

Syntax

trajectory ST_Resample(trajectory traj, config)

Parameters

ParameterDescription
trajThe trajectory to resample.
configA JSON string that specifies the resampling rule. Format: {"<rule_name>": <value>}. Only one rule can be specified per call.

Config rules

Add points

RuleValue typeEffect
add_point.distance_lesserFloating-point numberAdds points along the trajectory so that the distance between any two consecutive points is less than the specified value.
add_point.period_lesserString (INTERVAL-compatible, e.g., "2 day")Adds points along the trajectory so that the time gap between any two consecutive points is less than the specified value.

Remove points

RuleValue typeEffect
drop_point.distance_lesserFloating-point numberMerges consecutive segments whose total distance is less than the specified value, retaining only the start and end points of the merged segment.
drop_point.period_lesserString (INTERVAL-compatible, e.g., "2 day")Merges consecutive segments whose total duration is less than the specified value, retaining only the start and end points of the merged segment.

Description

ST_Resample applies the specified rule to a trajectory and returns the resampled result as a trajectory.

Only one rule can be specified per function call. To apply multiple rules, call ST_Resample multiple times in sequence.

Examples

Example 1: Add points so that the distance between consecutive points is less than 3.

SELECT ST_Resample(ST_MakeTrajectory('POINT(1 1)'), '{"add_point.distance_lesser":3}');

Output:

{"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-01 00:00:00","spatial":"POINT(1 1)","timeline":["2000-01-01 00:00:00"]}}
(1 row)

Example 2: Add points so that the time gap between consecutive points is less than 2 days.

SELECT ST_Resample(ST_MakeTrajectory('POINT(1 1)'), '{"add_point.period_lesser":"2 day"}');

Output:

{"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-01 00:00:00","spatial":"POINT(1 1)","timeline":["2000-01-01 00:00:00"]}}
(1 row)

Example 3: Remove points by merging segments whose total distance is less than 3.

SELECT ST_Resample(ST_MakeTrajectory('POINT(1 1)'), '{"drop_point.distance_lesser":3}');

Output:

{"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-01 00:00:00","spatial":"POINT(1 1)","timeline":["2000-01-01 00:00:00"]}}
(1 row)