ST_addEvent

更新时间:
复制 MD 格式

Adds an event to a trajectory object and returns a new trajectory with the event included.

Syntax

trajectory ST_addEvent(trajectory traj, integer event_type, timestamp event_time);

Parameters

ParameterTypeDescription
trajtrajectoryThe trajectory object to add the event to.
event_typeintegerThe event type ID.
event_timetimestampThe timestamp of the event.

Description

ST_addEvent returns a new trajectory object that includes the added event. The original trajectory object is not modified.

Event type IDs are predefined. For example, 1000 for unlocking and 2000 for locking.

The added event appears in the events array of the returned trajectory JSON.

Examples

The following example adds event type 1 at timestamp 2010-01-01 11:30:00 to a trajectory object.

WITH traj AS (
  SELECT '{"trajectory":{"version":1,"type":"STPOINT","leafcount":2,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 12:30:00","spatial":"SRID=4326;LINESTRING(1 1,3 5)","timeline":["2010-01-01 11:30:00","2010-01-01 12:30:00"],"attributes":{"leafcount":2,"velocity":{"type":"integer","length":4,"nullable":true,"value":[1,null]},"speed":{"type":"float","length":8,"nullable":true,"value":[null,1.0]},"angle":{"type":"string","length":64,"nullable":true,"value":["test",null]},"tngel2":{"type":"timestamp","length":8,"nullable":true,"value":["2010-01-01 12:30:00",null]},"bearing":{"type":"bool","length":1,"nullable":true,"value":[null,true]}}}}'::trajectory a)
SELECT ST_addEvent(a, 1, '2010-01-01 11:30:00') FROM traj;

The returned trajectory JSON includes a new "events":[{"1":"2010-01-01 11:30:00"}] field:

{"trajectory":{"version":1,"type":"STPOINT","leafcount":2,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 12:30:00","spatial":"SRID=4326;LINESTRING(1 1,3 5)","timeline":["2010-01-01 11:30:00","2010-01-01 12:30:00"],"attributes":{"leafcount":2,"velocity":{"type":"integer","length":4,"nullable":true,"value":[1,null]},"speed":{"type":"float","length":8,"nullable":true,"value":[null,1.0]},"angle":{"type":"string","length":64,"nullable":true,"value":["test",null]},"tngel2":{"type":"timestamp","length":8,"nullable":true,"value":["2010-01-01 12:30:00",null]},"bearing":{"type":"bool","length":1,"nullable":true,"value":[null,true]}},"events":[{"1":"2010-01-01 11:30:00"}]}}
(1 row)