ST_AsHMT
將一組trajectory對(duì)象按照指定范圍和指定分辨率轉(zhuǎn)換為熱力矩陣瓦片(HeatMapTile)。
語(yǔ)法
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, int4 value default 1, boolean point_mode default false);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, int4 value);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, int4 value, boolean point_mode);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, float8 value);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, float8 value, boolean point_mode);
返回值
返回一個(gè)基于protobuf的二進(jìn)制數(shù)據(jù)結(jié)構(gòu)用于表示每個(gè)網(wǎng)格點(diǎn)上數(shù)值。 proto文件如下所示:
syntax = "proto2";
option optimize_for = LITE_RUNTIME;
message HMT {
required Type type = 1; // data value type
required uint32 rows = 2; // rows of matrix
required uint32 columns = 3; // columns of matrix
required uint32 srid = 4; // columns of matrix
required float xmin = 5; // xmin
required float ymin = 6; // ymin
required float xmax = 7; // xmax
required float ymax = 8; // ymax
oneof matrix {
intMatrix intValues = 10;
doubleMatrix doubleValues = 11;
}
message intMatrix {
repeated sint32 values = 12 [packed = true];
}
message doubleMatrix {
repeated double values = 13 [packed = true];
}
enum Type {
INT32 = 0;
DOUBLE = 1;
}
}
類型(Type)根據(jù)參數(shù)傳入來(lái)確定,包括int32和double,前者可以計(jì)算數(shù)量等信息,后者可以計(jì)算指標(biāo)等信息。
rows為矩陣對(duì)應(yīng)的行數(shù),columns為矩陣對(duì)應(yīng)的列數(shù)。
matrix中數(shù)值為對(duì)應(yīng)Type類型的數(shù)組,按行方式進(jìn)行組織。
可通過(guò)ST_HMTAsArray函數(shù)將返回的結(jié)果轉(zhuǎn)換為數(shù)組的表示方式。
參數(shù)
參數(shù)名稱 | 描述 |
geometry_set | 聚合函數(shù)使用的幾何列字段。 |
extent | 需要統(tǒng)計(jì)的地理范圍,只獲取其外包框。可結(jié)合ST_TileEnvelope函數(shù)進(jìn)行使用。 |
width | 統(tǒng)計(jì)的網(wǎng)格的寬度,對(duì)應(yīng)到結(jié)果的columns。 |
height | 統(tǒng)計(jì)的網(wǎng)格的高度,對(duì)應(yīng)到結(jié)果的rows。 |
value | 需要進(jìn)行統(tǒng)計(jì)的數(shù)值,統(tǒng)計(jì)時(shí)會(huì)針對(duì)該數(shù)值進(jìn)行求和計(jì)算。 |
point_mode | 是否采用點(diǎn)模式,如使用點(diǎn)模式僅統(tǒng)計(jì)落入網(wǎng)格內(nèi)的點(diǎn)。 |
描述
將一組trajectory對(duì)象按照指定范圍和指定分辨率轉(zhuǎn)為熱力矩陣。
示例
-- create table
CREATE test_table AS
SELECT i as num,
st_maketrajectory('STPOINT'::leaftype,
st_MakeLine(ST_Point(i::numeric/10, i::numeric/10), ST_Point((i+10)::numeric/10, (i+10)::numeric/10)),
'[2010-01-01 14:30, 2010-01-01 15:30)'::tsrange, NULL) as traj,
i*100::int4 weight,
i*i*i::float8 volume
FROM generate_series(1, 100) i;
-- count quantity
SELECT ST_AsHMT(traj, --trajectory type
ST_MakeEnvelope(0, 0, 10, 10), -- Extent
1024, -- Width, in pixel
800 -- height
)
FROM test_table;
---------
\x080010a0061880083284...
-- count value
SELECT ST_AsHMT(traj, --trajectory type
ST_MakeEnvelope(0, 0, 10, 10), -- Extent
1024, -- Width
800, -- height
weight -- value column
)
FROM test_table;
---------
\x080010a0061880...
-- complex count
SELECT ST_AsHMT(traj, --trajectory type
ST_MakeEnvelope(0, 0, 10, 10), -- Extent
1024, -- Width
800, -- height
weight / volume * 1.2 -- complex value
)
FROM test_table;
---------
\x080110a0061880083a85...
-- point mode
SELECT ST_AsHMT(traj, --trajectory type
ST_MakeEnvelope(0, 0, 10, 10), -- Extent
1024, -- Width, in pixel
800, -- height,
1::integer, -- value
true -- point mode
)
FROM test_table;
---------
\x080010a0061880083...
-- where clause
SELECT ST_AsHMT(traj, --trajectory type
ST_MakeEnvelope(0, 0, 10, 10), -- Extent
1024, -- Width, in pixel
800 -- height
)
FROM test_table
WHERE num <5;
---------
\x080010a00618...