Trajectory thinning
Trajectory analysis involves computing and processing trajectory points to understand patterns and movement trends. Many redundant trajectory points can increase computation costs. You can use Lindorm spatiotemporal functions to perform trajectory thinning. This process filters redundant trajectory points, extracts feature data, and preserves trajectory patterns, which reduces computation costs.
Scenario description
The growth of the mobile Internet and the widespread use of mobile terminals generate large amounts of trajectory data from moving objects. Storing this data presents a significant challenge. To address this, LindormTable provides spatial data types and the Ganos service. These features allow you to store location information as POINT spatial data types or as FLOAT latitude and longitude values in LindormTable. You can also use spatiotemporal functions or build indexes to optimize query performance.
The following example shows how to use spatiotemporal functions to optimize queries in a trajectory analysis scenario:
An IoT Platform customer uses Lindorm to store trajectory data and needs to display the trajectories on a large screen in real-time. To reduce the frontend rendering workload, the trajectories are thinned based on specific rules and precision requirements. The following figure shows the results before and after thinning.

Technical implementation
The Lindorm Ganos spatiotemporal service provides the ST_Resample aggregate function. You can use this function to specify a thinning algorithm to achieve different trajectory thinning effects. This reduces the amount of data transmitted and the frontend rendering workload.
The ST_Resample function supports three spatial thinning (downsampling) algorithms:
Visvalingam-Whyatt algorithm: This algorithm recursively calculates the area of triangles formed by three consecutive points on the trajectory. It retains all points where the triangle area is greater than a specified tolerance.
Douglas-Peucker (DP) algorithm: This algorithm recursively finds the maximum perpendicular distance from each vertex between two endpoints to the line segment that connects them. It retains all points where the perpendicular distance is greater than a specified tolerance.
Topology Preserving DP algorithm: A version of the Douglas-Peucker algorithm that preserves the topology of the trajectory linestring.
The ST_Resample aggregate function also supports thinning by time interval. For more information, see ST_Resample.
Prerequisites
LindormTable is activated, and its version is 2.6.5 or later. For more information about how to view or upgrade the version, see LindormTable version guide and Minor version update.
The Lindorm Ganos spatiotemporal service is activated. For more information about how to activate the service, see Activate Spatio-Temporal Service (free of charge).
Step 1: Create a table and write test data
Create a table named `gps_points` with three columns: `account_id` for the device ID, `collect_time` for the data ingestion time, and `gps_point` for the trajectory point of the POINT data type.
CREATE TABLE gps_points (account_id VARCHAR, collect_time TIMESTAMP, gps_point GEOMETRY(POINT), PRIMARY KEY(account_id, collect_time));Write test data.
INSERT INTO gps_points(account_id, collect_time, gps_point) VALUES('001', '2023-11-10 11:00:30', ST_MakePoint(113.665431, 34.773)), ('001', '2023-11-10 11:00:31', ST_MakePoint(113.665432, 34.773)), ('001', '2023-11-10 11:00:32', ST_MakePoint(113.665433, 34.773)), ('001', '2023-11-10 11:00:33', ST_MakePoint(113.665434, 34.774));
Step 2: Perform a thinning query
Use the Ganos aggregate function ST_Resample to retrieve the thinning results with a single SQL statement.
The following example specifies the trajectory point column (`gps_point`) and the time column (`collect_time`). It fetches the trajectory points collected by the device with `account_id` '001' within a specified time period. The example also specifies the thinning algorithm and the downsampling distance threshold.
SELECT ST_Resample(gps_point, collect_time,'{"downsample_distance": 0.0001, "simplifier": "vw"}') as resampled_traj FROM gps_points WHERE collect_time >= '2023-11-10 00:00:00' and collect_time <= '2023-11-11 00:00:00' and account_id='001';The following result is returned:
+---------------------------------------------------------+
| resampled_traj |
+---------------------------------------------------------+
| [{"x":113.665431,"y":34.773,"t":"2023-11-10 |
| 11:00:30.0"},{"x":113.665434,"y":34.774,"t":"2023-11-10 |
| 11:00:33.0"}] |
+---------------------------------------------------------+The return value is a STRING that contains a sequence of trajectory points sorted by time after downsampling. The format is [{\"x\":longitude,\"y\":latitude,\"t\":time}, {\"x\":longitude,\"y\":latitude,\"t\":time}, ...].
Performance
When the table contains billions of rows, the timestamp range for a trajectory query can vary from a few hours to several days.
The following table shows the number of returned points for queries with and without the `ST_Resample` function. The queries were executed on a dataset of over one billion rows across different timestamp ranges.
Query timestamp range | With ST_Resample function | Without ST_Resample function |
1 hour | 9 | 405 |
1 day | 37 | 829 |
10 days | 118 | 8539 |
As shown in the table, for queries that cover a large data range, the ST_Resample function significantly reduces the number of returned points. This approach reduces data computation costs and simplifies the calculation method compared to queries that do not use the function.