You can use the ST_AsProtobuf function to transform a trajectory object to the Protobuf (Pbf) format for data exchange.
Syntax
bytea ST_AsProtobuf(trajectory traj);
Parameters
Parameter | Description |
traj | The trajectory that you want to transform. |
Return value
Returns a trajectory object in the Protobuf format.
See the following Protobuf definition:
syntax = "proto2";
option optimize_for = LITE_RUNTIME;
message Trajectory {
required uint32 srid = 1 [default = 4326]; // Srid
repeated Field fields = 2; // Fields definitions
repeated Point points = 3; // All trajectory Point
repeated Event events = 4; // Events
message Field {
required string name = 11; // Field Name
required FieldType type = 12; // Field Type
required uint32 length = 13; // Field length
required bool nullable = 14 [default = false]; // Field Nullable
}
message Value {
required bool is_null = 21 [default = false]; // Is null
oneof value_type {
string string_value = 22; // string value
double double_value = 23; // double value
float float_value = 24; // float value
sint32 int32_value = 25; // int32 value, int8 and int16 will in this value
sint64 int64_value = 26; // int64 value
bool bool_value = 27; // bool value
uint64 timestamp_value = 28; // timestamp value
}
}
enum FieldType {
string_type = 31;
double_type = 32;
integer_type = 33;
bool_type = 34;
timestamp_type = 35;
}
message Point {
required double x = 41; // x coordinate
required double y = 42; // y coordinate
optional double z = 43; // z value , optional
optional double m = 44; // m value, optional
required uint64 timestamp = 45; // timestamp
repeated Value attributes = 46; // all attribute values
}
message Event {
required int32 type = 51; // event type
required uint64 timestamp = 52; // timestamp
}
}
Description
The ST_AsProtobuf function is used to transform a trajectory object to the Protobuf format for data exchange or display.
Example
SELECT ST_AsProtobuf(ST_MakeTrajectory('STPOINT'::leaftype, st_geomfromtext('LINESTRING (114 35, 115 36, 116 37)', 4326), '[2010-01-01 14:30, 2010-01-01 15:30)'::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]}, "vesname": {"type": "string", "length": 20, "nullable" : true,"value": ["adsf", "sdf", "sdfff"]}, "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"}]}'));
---
st_asprotobuf
---------------------
\x08e62112105a0876656c6f63...