All Products
Search
Document Center

ApsaraDB RDS:ST_CompressSED

Last Updated:May 22, 2023

This topic describes the ST_CompressSED function. This function compresses a trajectory object based on specific rules. The compression is performed by using the Ramer–Douglas–Peucker (RDP) algorithm based on the synchronous Euclidean distance (SED) or a two-dimensional spatial distance and stay time of the trajectory object between two points.

Syntax

trajectoryST_CompressSed(trajectorytraj,float8dist);

Parameters

Parameter

Description

traj

The original trajectory object.

dist

The SED offset threshold. After a value is specified, trajectory points whose SED offset is greater than the value are kept so that the spatial trend of the original trajectory object is retained.

Description

This function calculates the SED of trajectory points, discards the points whose SED offset is smaller than the value of the dist parameter to compress the trajectory object, and then returns the compressed trajectory object.

The RDP algorithm applies on only two-dimensional trajectories. All points on a two-dimensional trajectory object are on a plane. In this case, if the trajectory object is a spatio-temporal trajectory or a three-dimensional polyline, the following issues occur:

If the trajectory object stays at a point for a long period of time, the trajectory object becomes a line segment parallel to the t-axis in the three-dimensional space or a new point in the two-dimensional space. If you use the RDP algorithm based on a two-dimensional spatial distance, the start or end point of the long line segment in the three-dimensional space is discarded. This destroys the trajectory object in the three-dimensional space.

Therefore, when a timestamp exists, we recommend that you use the SED instead of the vertical Euclidean distance.

SED: If the start and end points of the long line segment are (xs,ys,ts) and (xe,ye,te) and the new point is (xm,ym,tm), you must find the tm point (xm', ym', tm) by adding a point to the long line segment, and then calculate the distance between the points (xm,ym) and (xm', ym'). In this calculation, you must know that ts ≤ tm ≤ te. The distance that is calculated is the SED.

Note

If you do not want to compress a trajectory object based on the stay time of a trajectory object between two points, you can call the ST_Compress function.

Examples

select st_compressSED(traj, 0.001) as traj from traj_test;
           traj
-------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":12,"start_time":"2017-01-15 09:06:39","end_time":"2017-01-15 21:18:30","spatial":"LINESTRING(-179.48077 51.72814,-179.42595 51.80094,-179.39734 51.83398,-179.37474 51.86568,-179.18826 52.10105,-179.16482 52.12996,-179.14599 52.15132,-177.76666 52.85042,-177.47319 52.90084,-177.31238 52.92697,-177.03751 52.97394,-176.68481 53.03327)","timeline":["2017-01-15 09:06:39","2017-01-15 09:34:40","2017-01-15 09:47:38","2017-01-15 09:59:09","2017-01-15 11:30:09","2017-01-15 11:42:00","2017-01-15 11:50:28","2017-01-15 18:01:00","2017-01-15 18:56:22","2017-01-15 19:26:10","2017-01-15 20:15:49","2017-01-15 21:18:30"],"attributes":{"leafcount":12,"sog":{"type":"float","length":8,"nullable":false,"value":[10.5,11.0,10.6,11.2,9.1,9.7,9.9,12.3,12.0,12.2,12.8,12.7]},"cog":{"type":"float","length":8,"nullable":false,"value":[23.3,28.5,29.2,27.1,26.8,30.1,30.0,74.2,81.3,73.4,74.2,72.9]},"heading":{"type":"float","length":8,"nullable":false,"value":[22.0,27.0,24.0,29.0,27.0,26.0,27.0,69.0,72.0,71.0,72.0,73.0]}}}}
(1 row)