トラジェクトリ オブジェクトを構築します。
構文
-
構文 1
trajectory ST_makeTrajectory(leaftype type, geometry spatial, tsrange timespan, cstring attrs_json); -
構文 2
trajectory ST_makeTrajectory(leaftype type, geometry spatial, timestamp start, timestamp end, cstring attrs_json); -
構文 3
trajectory ST_makeTrajectory(leaftype type, geometry spatial, timestamp[] timeline, cstring attrs_json); -
構文 4
trajectory ST_makeTrajectory(leaftype type, float8[] x, float8[] y, integer srid, timestamp[] timeline, text[] attr_field_names, int4[] attr_int4, float8[] attr_float8, text[] attr_cstring, anyarray attr_any); -
構文 5
trajectory ST_makeTrajectory(anyarray rows, bool hasz, cstring[] attrnames);
パラメーター
|
パラメーター |
説明 |
|
type |
トラジェクトリのタイプです。現在、ST_POINT のみがサポートされています。 |
|
spatial |
LineString または Point タイプに基づくトラジェクトリの空間オブジェクトです。 |
|
timespan |
tsrange 型で指定する、開始時刻と終了時刻を含む期間です。 |
|
start |
トラジェクトリの開始時刻です。 |
|
end |
トラジェクトリの終了時刻です。 |
|
timeline |
トラジェクトリのタイムラインです。時刻ポイントの数は、LineString 内のポイントの数と一致する必要があります。 |
|
attrs_json |
JSON 形式のトラジェクトリの属性とイベントです。このパラメーターは NULL に設定できます。 |
|
attr_field_names |
トラジェクトリの属性を表す、すべてのフィールドの名前の配列です。 |
|
x |
ジオメトリ オブジェクトの構築に使用される x 座標の配列です。 |
|
y |
ジオメトリ オブジェクトの構築に使用される y 座標の配列です。 |
|
srid |
空間参照系識別子です。このパラメーターは必須です。 |
|
rows |
トラジェクトリを表すために使用されるテーブルです。最初の列は TimeStamp 型、2 番目と 3 番目の列は float8 型でなければなりません。 |
|
hasz |
トラジェクトリが 3次元であるかどうかを指定します。
|
|
attrnames |
トラジェクトリ内の属性の名前です。このパラメーターを指定しない場合、デフォルト値は |
-
attrs_json の形式は次のとおりです:
{ "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" } ] }リーフカウント:トラジェクトリに含まれるトラジェクトリ ポイントの数です。この値は、空間オブジェクト内の空間ポイントの数と一致する必要があります。また、この値は各属性フィールドに含まれる要素の値の数でもあります。すべての属性フィールドには、同じ数の要素を含む必要があります。
属性:すべての属性のフィールド定義と値のシーケンスを含む属性項目です。このパラメーターは、leafcount と同時に指定する必要があります。属性の定義と要件は次のとおりです:
-
属性名は最大 60 文字まで使用できます。
-
type:フィールド タイプです。integer、float、文字列、timestamp、bool の 5 つのデータ型がサポートされています。
-
length:フィールド長です。
-
integer は、1、2、4、または 8 の長さをサポートします。
-
float は、4 または 8 の長さをサポートします。
-
文字列はカスタム長をサポートします。長さを指定しない場合、デフォルトの長さは 64 です。最大長は 253 です。長さの値は実際の文字数であり、終端識別子は含まれません。
-
timestamp の長さはオプションです。デフォルト値は 8 です。
-
bool の長さはオプションです。デフォルト値は 1 です。
-
-
nullable:フィールドが NULL 値を許容するかどうかを指定します。true は NULL 値を許容し、false は許容しません。デフォルト値は true です。
-
value:フィールド値のシーケンスです。JSON 配列として表現されます。NULL の要素値は null として表現されます。
イベント:トラジェクトリのイベントです。複数のイベントは JSON 配列として表現されます。各配列要素は JSON の "key:value" ペアとして表現され、キーはイベントタイプ、値はイベント時刻です。
-
-
指定する時間パラメーターが timespan または start と end の場合、時刻ポイントは spatial 内のポイント数に基づいて補間されます。
-
関数
array_agg(row(table.*))を使用して、テーブルの行を集計し、トラジェクトリに変換できます。詳細については、「構文 5」をご参照ください。 -
上記のどの構文も要件を満たさない場合は、MakeTrajectory 関数をカスタマイズできます。最初の 6 つのパラメーターは固定されており、後続のパラメーターはビジネス要件に基づいてカスタマイズできます。
CREATE OR REPLACE FUNCTION _ST_MakeTrajectory(type leaftype, x float8[], y float8[] , srid integer, timespan timestamp[], attrs_name cstring[], attr1 float8[], attr2 float4[], attr3 timestamp[]) RETURNS trajectory AS '$libdir/libpg-trajectory-x.y','sqltr_traj_make_all_array' LANGUAGE 'c' IMMUTABLE Parallel SAFE;説明この例では、
x.yは GanosBase のバージョンであり、ST_Version を実行することで確認できます。たとえば、バージョン 4.5 の場合、値はlibpg-trajectory-4.5です。カスタム関数を作成する際に権限エラーが発生した場合は、チケットをサブミットしてください。
例
-- (1) タイムスタンプ範囲を指定した ST_MakeTrajectory
select 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_maketrajectory
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":3,"start_time":"2010-01-01 14:30:00","end_time":"2010-01-01 15:30:00","spatial":"SRID=4326;LINESTRING(114 35,115 36,116 37)","timeline":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00"],"attributes":{"leafcount":3,"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120.0,130.0,140.0]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120.0,130.0,140.0]},"vesname":{"type":"string","length":20,"nullable":true,"value":["adsf","sdf","sdfff"]},"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"]}},"events":[{"1":"2010-01-01 14:30:00"},{"2":"2010-01-01 15:00:00"},{"3":"2010-01-01 15:30:00"}]}}
(1 row)
-- (2) 開始タイムスタンプと終了タイムスタンプを指定した ST_MakeTrajectory
select ST_MakeTrajectory('STPOINT'::leaftype, st_geomfromtext('LINESTRING (114 35, 115 36, 116 37)', 4326), '2010-01-01 14:30'::timestamp, '2010-01-01 15:30'::timestamp, '{"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_maketrajectory
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":3,"start_time":"2010-01-01 14:30:00","end_time":"2010-01-01 15:30:00","spatial":"SRID=4326;LINESTRING(114 35,115 36,116 37)","timeline":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00"],"attributes":{"leafcount":3,"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120.0,130.0,140.0]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120.0,130.0,140.0]},"vesname":{"type":"string","length":20,"nullable":true,"value":["adsf","sdf","sdfff"]},"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"]}},"events":[{"1":"2010-01-01 14:30:00"},{"2":"2010-01-01 15:00:00"},{"3":"2010-01-01 15:30:00"}]}}
(1 row)
-- (3) タイムスタンプ配列を指定した ST_MakeTrajectory
select ST_MakeTrajectory('STPOINT'::leaftype, st_geomfromtext('LINESTRING (114 35, 115 36, 116 37)', 4326), ARRAY['2010-01-01 14:30'::timestamp, '2010-01-01 15:00'::timestamp, '2010-01-01 15:30'::timestamp], '{"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_maketrajectory
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":3,"start_time":"2010-01-01 14:30:00","end_time":"2010-01-01 15:30:00","spatial":"SRID=4326;LINESTRING(114 35,115 36,116 37)","timeline":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00"],"attributes":{"leafcount":3,"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120.0,130.0,140.0]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120.0,130.0,140.0]},"vesname":{"type":"string","length":20,"nullable":true,"value":["adsf","sdf","sdfff"]},"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"]}},"events":[{"1":"2010-01-01 14:30:00"},{"2":"2010-01-01 15:00:00"},{"3":"2010-01-01 15:30:00"}]}}
(1 row)
-- (4) json が NULL の場合
select 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, null);
st_maketrajectory
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":3,"start_time":"2010-01-01 14:30:00","end_time":"2010-01-01 15:30:00","spatial":"SRID=4326;LINESTRING(114 35,115 36,116 37)","timeline":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00"]}}
(1 row)
-- (5) ポイントから作成する ST_MakeTrajectory
select st_makeTrajectory('STPOINT'::leaftype, ARRAY[1::float8], ARRAY[2::float8], 4326, ARRAY['2010-01-01 11:30'::timestamp], ARRAY['velocity'], ARRAY[1::int4], NULL, NULL, NULL::anyarray);
st_maketrajectory
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 11:30:00","spatial":"SRID=4326;POINT(1 2)","timeline":["2010-01-01 11:30:00"],"attributes":{"leafcount":1,"velocity":{"type":"integer","length":4,"nullable":true,"value":[1]}}}}
(1 row)
-- (6) テーブルから作成する ST_MakeTrajectory
CREATE TABLE tjrows(t timestamp, x double precision, y double precision, id int, attr text);
INSERT into tjrows values ('2000-01-01 10:00:00', 3, 5, 1, '最初のポイント'), ('2000-01-01 11:00:00', 4, 6,2, '2番目のポイント'), ('2000-01-01 11:05:00', 5,7,3,'3番目のポイント');
select ST_MakeTrajectory(array_agg(row(tjrows.*)), false, '{"id","attr"}'::cstring[]) from tjrows;
st_maketrajectory
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------
{"trajectory":{"version":1,"type":"STPOINT","leafcount":3,"start_time":"2000-01-01 10:00:00","end_time":"2000-01-01 11:05:00","spatial":"LINESTRING(3 5,4 6,5 7)","timeline":["2000-01-01 10:00:00",
"2000-01-01 11:00:00","2000-01-01 11:05:00"],"attributes":{"leafcount":3,"id":{"type":"integer","length":4,"nullable":true,"value":[1,2,3]},"attr":{"type":"string","length":64,"nullable":true,"valu
e":["最初のポイント","2番目のポイント","3番目のポイント"]}}}}
(1 row)