Appends trajectory points or a sub-trajectory to a trajectory object.
Syntax
trajectory ST_append(trajectory traj, geometry spatial, timestamp[] timespan, text str_attrs_json);
trajectory ST_append(trajectory traj, trajectory tail);The first overload appends individual trajectory points defined by geometry, timestamps, and attributes. The second overload appends an entire sub-trajectory.
Parameters
| Parameter | Description |
|---|---|
traj | The original trajectory object. |
spatial | The geometry of the trajectory points to append. |
timespan | The timestamp array for the appended points. Can be a timeline. |
str_attrs_json | The attributes of the appended points, in JSON format. For the JSON schema, see ST_makeTrajectory. |
tail | The sub-trajectory to append. |
Examples
Append a sub-trajectory (second overload)
This example builds two trajectory objects and appends the second to the first using the tail overload. Each trajectory has type STPOINT, three spatial points (LINESTRING), five attributes, and three events.
WITH traj AS (
SELECT
ST_makeTrajectory('STPOINT', 'LINESTRING(1 1, 6 6, 9 8)'::geometry,
'[2010-01-01 11:30, 2010-01-01 15:00)'::tsrange,
'{"leafcount":3,"attributes":{"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120,130,140]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120,130,140]},"acceleration":{"type":"string","length":20,"nullable":true,"value":["120","130","140"]},"active":{"type":"timestamp","nullable":false,"value":["Fri Jan 01 14:30:00 2010","Fri Jan 01 15:00:00 2010","Fri Jan 01 15:30:00 2010"]}},"events":[{"1":"Fri Jan 01 14:30:00 2010"},{"2":"Fri Jan 01 15:00:00 2010"},{"3":"Fri Jan 01 15:30:00 2010"}]}'
) a,
ST_makeTrajectory('STPOINT', 'LINESTRING(7 7, 3 4, 1 5)'::geometry,
'[2010-01-02 15:30, 2010-01-02 18:00)'::tsrange,
'{"leafcount":3,"attributes":{"velocity":{"type":"integer","length":2,"nullable":true,"value":[121,131,141]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[121,131,141]},"bearing":{"type":"float","length":8,"nullable":false,"value":[121,131,141]},"acceleration":{"type":"string","length":20,"nullable":true,"value":["121","131","141"]},"active":{"type":"timestamp","nullable":false,"value":["Fri Jan 02 14:30:00 2010","Fri Jan 02 15:00:00 2010","Fri Jan 02 15:30:00 2010"]}},"events":[{"1":"Fri Jan 02 14:30:00 2010"},{"2":"Fri Jan 02 15:00:00 2010"},{"3":"Fri Jan 02 15:30:00 2010"}]}'
) b
)
SELECT ST_append(a, b) FROM traj;The result is a merged trajectory with leafcount=6, covering the combined spatial path and time range:
{"trajectory":{"version":1,"type":"STPOINT","leafcount":6,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-02 18:00:00","spatial":"LINESTRING(1 1,6 6,9 8,7 7,3 4,1 5)","timeline":["2010-01-01 11:30:00","2010-01-01 13:15:00","2010-01-01 15:00:00","2010-01-02 15:30:00","2010-01-02 16:45:00","2010-01-02 18:00:00"],"attributes":{"leafcount":6,"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140,121,131,141]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120.0,130.0,140.0,121.0,131.0,141.0]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120.0,130.0,140.0,121.0,131.0,141.0]},"acceleration":{"type":"string","length":20,"nullable":true,"value":["120","130","140","121","131","141"]},"active":{"type":"timestamp","length":8,"nullable":false,"value":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00","2010-01-02 14:30:00","2010-01-02 15:00:00","2010-01-02 15:30:00"]}},"events":[{"1":"2010-01-01 14:30:00"},{"2":"2010-01-01 15:00:00"},{"3":"2010-01-01 15:30:00"},{"1":"2010-01-02 14:30:00"},{"2":"2010-01-02 15:00:00"},{"3":"2010-01-02 15:30:00"}]}}Key observations:
leafcountincreases from 3 to 6 — all points from both trajectories are merged.spatialbecomesLINESTRING(1 1,6 6,9 8,7 7,3 4,1 5)— the path segments are concatenated in order.timelinespans from2010-01-01 11:30:00to2010-01-02 18:00:00— timestamps from both trajectories are preserved.Attribute arrays for all five fields are concatenated in order.
Events from both trajectories are preserved in the merged result.
See also
ST_makeTrajectory — construct a trajectory object