Trajectory generation
In Internet of Vehicles (IoV) scenarios, real-time location points from vehicles are aggregated into a trajectory. Each new location point is appended to this trajectory for easier analysis and prediction. This process involves real-time uploads and a large data volume. As a result, the database consumes significant I/O resources when appending data. To solve this problem, the Lindorm Ganos spatiotemporal service combines with the real-time computing capabilities of Lindorm Stream to provide a trajectory generation solution. This topic describes the technical implementation and procedure for trajectory generation.
Background information
In IoV scenarios, vehicles continuously upload location point (GPS point) data. These points form a trajectory (Trajectory or LineString). You can use these trajectories to perform efficient analysis and prediction. For example, you can trace a vehicle's historical path, identify common routes from multiple trajectories, or calculate the similarity between trajectories.
In an Internet of Vehicles (IoV) scenario, for example, the location points of two vehicles can be stitched together every hour to form a trajectory.

Technical implementation
Aggregating location points into a trajectory is an append operation. Each new point is appended to an existing trajectory.
At the database level, this process involves frequent read-write aggregation operations. The database first reads the existing trajectory data. Then, it aggregates the new location point with the existing trajectory in memory to form a new trajectory. Finally, it writes the new trajectory back to the database. This process is I/O-intensive. If the data volume is too large, it can affect query response times.
To solve this problem, the Lindorm Ganos spatiotemporal service provides a trajectory generation solution based on Lindorm Stream. Lindorm Stream reads real-time location point data from vehicles. It periodically stitches the points into trajectories, such as every hour or day. Then, it writes the aggregated trajectory data to the database. This approach ensures real-time processing and analysis of vehicle trajectory data. It also reduces the I/O pressure on the database from high-frequency append operations.
Trajectory generation involves one type of source data: real-time vehicle location data.
Vehicle location information is streaming data that is uploaded in real time. You can save this data to a Kafka topic. Lindorm Stream reads the location data from the Kafka topic, performs real-time computing based on a task, and saves the results to a Lindorm wide table.
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.
Lindorm Stream is activated. For more information, see Activate Lindorm Stream.
The client IP address is added to the Lindorm whitelist. For more information, see Set a whitelist.
Notes
If your application is deployed on an ECS instance and accesses a Lindorm instance over a VPC, ensure that the Lindorm instance and the ECS instance meet the following conditions to ensure network connectivity.
They are in the same region. We recommend that they are also in the same zone to reduce network latency.
The ECS instance and the Lindorm instance are in the same VPC.
Step 1: Create a sink table
Create a sink table in LindormTable to store and query the computation results.
Create a sink table named resultAgg1. The table includes five fields: cid (vehicle ID), stt (window start time), edd (window end time), line (trajectory), and timeseries (timestamp).
CREATE TABLE resultAgg1(cid INT, stt TIMESTAMP, edd TIMESTAMP, line VARCHAR, timeseries VARCHAR, PRIMARY KEY (cid,stt));
Step 2: Write streaming data
Lindorm Stream is fully compatible with open source Kafka APIs. You can connect to Lindorm Stream and write test data using an open source Kafka client or script.
The following example shows how to write data using an open source Kafka script.
Download and install the Kafka script tool. For more information, see Connect to Lindorm Stream using an open source Kafka script.
Run the following command to create a Kafka topic named tdrive.
bin/kafka-topics.sh --bootstrap-server <Lindorm Stream Kafka endpoint> --topic tdrive --createThe Lindorm Stream Kafka endpoint is the Kafka endpoint of Lindorm Stream. Only access over a VPC is supported. To obtain the endpoint, see View endpoints.
Run the following command to write the sample data in
car1.txt(test location point data) to the Kafka topic. Download the sample data: car1.txt../bin/kafka-console-producer.sh --bootstrap-server <Lindorm Stream Kafka endpoint> --topic tdrive < car1.txt
Step 3: Submit a Lindorm Stream computing job
Use Flink SQL to submit a Lindorm Stream computing job that reads and computes data from the Kafka topic.
Connect to Lindorm Stream. For more information, see Step 2: Install the Lindorm Stream client.
Submit the computing job.
The computing job stitches the points written to the Kafka topic into a trajectory based on a specified time window and order. The procedure is as follows:
Load the
ganosfunction module.In the Flink Job, create two tables: a data source table named tdrive and a sink table named resultAgg1. Set the connector parameters to associate them with the Kafka topic and the resultAgg1 sink table that you created, respectively.
Create a streaming task. Use the
ST_MakeLine_Ts_Aggfunction to stitch the points into a trajectory and sort the data by the input timestamp column. Use theLISTAGGfunction to concatenate the timestamps. Finally, write the computation results to the resultAgg1 sink table.
CREATE FJOB lineAgg1 ( LOAD MODULE ganos; -- create stream table CREATE TABLE tdrive( cid INT, ts TIMESTAMP(0), lng DOUBLE, lat DOUBLE, WATERMARK FOR ts AS ts-INTERVAL '10' MINUTES ) WITH ( 'connector'='kafka', 'topic'='tdrive', 'scan.startup.mode'='earliest-offset', 'properties.bootstrap.servers'='<Lindorm Stream Kafka endpoint>', 'format'='json', 'json.ignore-parse-errors'='true' ); --create result table CREATE TABLE resultAgg1( cid INT, stt TIMESTAMP(0), edd TIMESTAMP(0), line STRING, PRIMARY KEY(cid,stt) NOT ENFORCED ) WITH ( 'connector'='lindorm', 'seedServer'='<HBase Java API endpoint of LindormTable>', 'userName'='<Username for LindormTable>', 'password'='<Password for LindormTable>', 'tableName'='resultAgg1', 'namespace'='<Database where the resultAgg1 sink table is located>'); INSERT INTO resultAgg1 SELECT cid, window_start AS stt, window_end AS edd, ST_AsText(ST_MakeLine_Ts_Agg(ST_MakePoint(lng,lat),ts)) AS line, LISTAGG(CAST(ts AS VARCHAR)) AS timeseries FROM TABLE(TUMBLE(TABLE tdrive, DESCRIPTOR(ts), INTERVAL '1' HOUR)) WHERE lng IS NOT NULL AND lat IS NOT NULL AND ST_IsEmpty(ST_MakePoint(lng,lat))=false GROUP BY window_start,window_end,cid; );NoteTo obtain the HBase Java API endpoint for LindormTable, see View endpoints.
For more information about the functions used in the computing job, see ST_AsText, ST_MakePoint, ST_MakeLine_Ts_Agg, and TUMBLE window function.
Step 4: View the results
Run the following statement to view the aggregation results.
SELECT * FROM resultAgg1 LIMIT 5;The following result is returned:
+-----+-------------------------------+-------------------------------+--------------------------------+--------------------------------+ | cid | stt | edd | line | timeseries | +-----+-------------------------------+-------------------------------+--------------------------------+--------------------------------+ | 1 | 2008-02-02 15:00:00 +0000 UTC | 2008-02-02 16:00:00 +0000 UTC | LINESTRING (116.51172 | 2008-02-02 | | | | | 39.92123, 116.51135 39.93883, | 07:36:08.000,2008-02-02 | | | | | 116.51627 39.91034) | 07:46:08.000,2008-02-02 | | | | | | 07:56:08.000 | | 1 | 2008-02-02 16:00:00 +0000 UTC | 2008-02-02 17:00:00 +0000 UTC | LINESTRING (116.47186 | 2008-02-02 | | | | | 39.91248, 116.47217 39.92498, | 08:06:08.000,2008-02-02 | | | | | 116.47179 39.90718, 116.45617 | 08:16:08.000,2008-02-02 | | | | | 39.90531) | 08:26:08.000,2008-02-02 | | | | | | 08:36:08.000 | | 1 | 2008-02-02 17:00:00 +0000 UTC | 2008-02-02 18:00:00 +0000 UTC | LINESTRING (116.47191 | 2008-02-02 | | | | | 39.90577, 116.50661 39.9145) | 09:00:24.000,2008-02-02 | | | | | | 09:10:24.000 | | 1 | 2008-02-02 20:00:00 +0000 UTC | 2008-02-02 21:00:00 +0000 UTC | LINESTRING (116.49625 39.9146, | 2008-02-02 | | | | | 116.50962 39.91071, 116.52231 | 12:30:34.000,2008-02-02 | | | | | 39.91588) | 12:40:33.000,2008-02-02 | | | | | | 12:50:33.000 | | 1 | 2008-02-02 21:00:00 +0000 UTC | 2008-02-02 22:00:00 +0000 UTC | LINESTRING (116.56444 | 2008-02-02 | | | | | 39.91445, 116.59512 39.90798, | 13:00:33.000,2008-02-02 | | | | | 116.65522 39.8622, 116.69164 | 13:10:33.000,2008-02-02 | | | | | 39.85165, 116.69167 39.85166) | 13:30:33.000,2008-02-02 | | | | | | 13:40:33.000,2008-02-02 | | | | | | 13:50:33.000 | +-----+-------------------------------+-------------------------------+--------------------------------+--------------------------------+The `line` column contains the aggregated trajectory, and the `timeseries` column contains the timestamps that correspond to the location points.