Returns the defined length of a trajectory attribute field.
Syntax
integer ST_attrLength(trajectory traj, integer index);
integer ST_attrLength(trajectory traj, text name);Parameters
| Parameter | Description |
|---|---|
traj | The trajectory object. |
index | The index of the attribute field. |
name | The name of the attribute field. |
Examples
The following examples use a trajectory object with five attributes: velocity (integer, 4 bytes), speed (float, 8 bytes), angle (string, 64 bytes), tngel2 (timestamp, 8 bytes), and bearing (bool, 1 byte).
Query by index
Retrieve the defined length of the first attribute field (index 0, which is velocity):
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_attrLength(a, 0) from traj;Result:
st_attrlength
---------------
4
(1 row)Query by name
Retrieve the defined length of the velocity attribute field by name:
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_attrLength(a, 'velocity') from traj;Result:
st_attrlength
---------------
4
(1 row)该文章对您有帮助吗?