Events let you attach time-stamped business occurrences to a trajectory, separate from the trajectory's regular sampling points. Unlike attribute information, events don't need to align with a sampling point — an event can occur at any timestamp, even between two recorded positions.
Example use cases: recording when a delivery truck is refueled, loaded, or unloaded along its route.
How it works
Each event has two required values:
Event ID — an integer that identifies the type of business occurrence. Define your own mapping. For example: refueling =
1001, loading =1002, unloading =1003.Event timestamp — the exact time the occurrence happened. This timestamp does not have to match any sampling point in the trajectory.
Add an event
Use ST_AddEvent to attach an event to a trajectory stored in a column.
Example: The truck belonging to user ID 1 was refueled at 17:45:00 on April 11, 2020. Assign event ID 1001 to the refueling event and add it to the trajectory:
UPDATE trajectory_table
SET traj = ST_AddEvent(traj, 1001, '2020-04-11 17:45:00')
WHERE userid = 1;