ST_AsProtobuf

更新时间:
复制 MD 格式

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 name

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]; // The spatial reference identifier (SRID).
  repeated Field fields = 2; // The field definitions.
  repeated Point points = 3; // All trajectory points.
  repeated Event events = 4; // The events.

  message Field {
    required string name = 11; // The field name. 
    required FieldType type = 12; // The field type.
    required uint32 length = 13;  // The field length.
    required bool nullable = 14 [default = false]; // Specifies whether the field can be null.
  }

  message Value {  
    required bool is_null = 21 [default = false]; // Specifies whether the value is null.  
    oneof value_type {      
      string string_value = 22; // The string value.
      double double_value = 23; // The double value.
      float float_value = 24; // The float value.
      sint32 int32_value = 25; // The int32 value. This field also stores int8 and int16 values.
      sint64 int64_value = 26; // The int64 value.
      bool bool_value = 27; // The Boolean value.
      uint64 timestamp_value = 28; // The 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; // The x-coordinate.
    required double y = 42; // The y-coordinate.
    optional double z = 43; // The z-coordinate. This parameter is optional.
    optional double m = 44; // The m-coordinate. This parameter is optional.
    required uint64 timestamp = 45; // The timestamp.

    repeated Value attributes = 46; // All attribute values.
  }

  message Event {
    required int32 type = 51; // The event type.
    required uint64 timestamp = 52; // The 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...