All Products
Search
Document Center

ApsaraDB RDS:ST_Resample

Last Updated:Sep 05, 2023

This topic describes the ST_Resample function. This function resamples a trajectory.

Syntax

trajectory ST_Resample(trajectory traj, config);

Parameters

Parameter

Description

traj

The trajectory that is resampled.

config

The rule that is used to resample the trajectory. Format: {"Rule":"Value"}.

Only one rule can be specified by the config parameter. The following table describes the rules that you can specify by using the config parameter.

Rule

Type

Description

add_point.distance_lesser

Floating point

Evenly add points to each trajectory so that the distance between two points is smaller than the parameter value.

add_point.period_lesser

String that can be converted into the INTERVAL type

Evenly add points to each trajectory so that the period of time between two points is smaller than the parameter value.

drop_point.distance_lesser

Floating point

When the distance between all points of consecutive segments of a trajectory and the start point of the trajectory is less than the value of this rule, the consecutive segments are merged. Only the start and end points of the obtained segment are retained.

drop_point.period_lesser

String that can be converted into the INTERVAL type

When the sum of time of periods required between multiple consecutive segments of a trajectory is less than the given period of time, merge the consecutive segments. Only the start and end points of the obtained segment are retained.

Description

This function resamples a trajectory based on the specified rule and returns the resampling result.

Examples

With traj As
(
  select '{"trajectory":{"version":1,"type":"STPOINT","leafcount":5,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"LINESTRING(1 1,10 10,11 11,13 13,15 15)","timeline":["2000-01-01 00:00:00","2000-01-02 00:00:00","2000-01-03 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00"]}}'::trajectory a
)
SELECT ST_Resample(a, '{"add_point.distance_lesser":3}') from traj;
                                                                                                                                                                                                              st_resample                                                                                                                                                                                                               
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"trajectory":{"version":1,"type":"STPOINT","leafcount":9,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"LINESTRING(1 1,2.8 2.8,4.6 4.6,6.4 6.4,8.2 8.2,10 10,11 11,13 13,15 15)","timeline":["2000-01-01 00:00:00","2000-01-01 04:48:00","2000-01-01 09:36:00","2000-01-01 14:24:00","2000-01-01 19:12:00","2000-01-02 00:00:00","2000-01-03 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00"]}}
(1 row)

With traj As
(
  select '{"trajectory":{"version":1,"type":"STPOINT","leafcount":5,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"LINESTRING(1 1,10 10,11 11,13 13,15 15)","timeline":["2000-01-01 00:00:00","2000-01-02 00:00:00","2000-01-03 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00"]}}'::trajectory a
)
SELECT ST_Resample(a, '{"add_point.period_lesser":"0.5 day"}') from traj;
                                                                                                                                                                                                             st_resample                                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"trajectory":{"version":1,"type":"STPOINT","leafcount":9,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"LINESTRING(1 1,5.5 5.5,10 10,10.5 10.5,11 11,12 12,13 13,14 14,15 15)","timeline":["2000-01-01 00:00:00","2000-01-01 12:00:00","2000-01-02 00:00:00","2000-01-02 12:00:00","2000-01-03 00:00:00","2000-01-03 12:00:00","2000-01-04 00:00:00","2000-01-04 12:00:00","2000-01-05 00:00:00"]}}
(1 row)

With traj As
(
  select '{"trajectory":{"version":1,"type":"STPOINT","leafcount":5,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"LINESTRING(1 1,10 10,11 11,13 13,15 15)","timeline":["2000-01-01 00:00:00","2000-01-02 00:00:00","2000-01-03 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00"]}}'::trajectory a
)
SELECT ST_Resample(a, '{"drop_point.distance_lesser":3}') from traj;
                                                                                                                                    st_resample                                                                                                                                     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"trajectory":{"version":1,"type":"STPOINT","leafcount":4,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-05 00:00:00","spatial":"LINESTRING(1 1,10 10,13 13,15 15)","timeline":["2000-01-01 00:00:00","2000-01-02 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00"]}}
(1 row)