All Products
Search
Document Center

PolarDB:ST_Resample

Last Updated:Mar 28, 2026

Resamples a trajectory by adding or removing points to meet a distance or time threshold.

Syntax

trajectory ST_Resample(trajectory traj, config);

Parameters

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

Resampling rules

Rule nameValue typeEffect
add_point.distance_lesserFloating-pointAdds intermediate points so that the distance between two consecutive points is smaller than the specified distance.
add_point.period_lesserString (interval)Adds intermediate points so that the period of time between two consecutive points is smaller than the specified time.
drop_point.distance_lesserFloating-pointRemoves intermediate points from consecutive segments whose combined length is less than the specified distance, keeping only the start and end points of the merged segment.
drop_point.period_lesserString (interval)Removes intermediate points from consecutive segments whose combined duration is less than the specified time, keeping only the start and end points of the merged segment.

Description

ST_Resample resamples a trajectory based on the specified rule and returns an array of sub-trajectories.

Examples

The following examples use a single-point trajectory created with ST_MakeTrajectory.

Add points by distance threshold

Adds points so that the distance between two consecutive points is smaller than 3 units:

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

Output:

                                                                                        st_resample
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"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)

Add points by time threshold

Adds points so that the period of time between two consecutive points is smaller than 2 days:

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

Output:

                                                                                        st_resample
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"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)

Remove points by distance threshold

Removes intermediate points from consecutive segments whose combined length is less than 3 units, keeping only the start and end points:

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

Output:

                                                                                        st_resample
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"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)