文档

ST_AsHMT

更新时间:

将一组trajectory对象按照指定范围和指定分辨率转换为热力矩阵瓦片(HeatMapTile)。

语法

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);

返回值

返回一个基于protobuf的二进制数据结构用于表示每个网格点上数值。 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)根据参数传入来确定,包括int32和double,前者可以计算数量等信息,后者可以计算指标等信息。

  • rows为矩阵对应的行数,columns为矩阵对应的列数。

  • matrix中数值为对应Type类型的数组,按行方式进行组织。

  • 可通过ST_HMTAsArray函数将返回的结果转换为数组的表示方式。

参数

参数名称

描述

geometry_set

聚合函数使用的几何列字段。

extent

需要统计的地理范围,只获取其外包框。可结合ST_TileEnvelope函数进行使用。

width

统计的网格的宽度,对应到结果的columns。

height

统计的网格的高度,对应到结果的rows。

value

需要进行统计的数值,统计时会针对该数值进行求和计算。

point_mode

是否采用点模式,如使用点模式仅统计落入网格内的点。

描述

将一组trajectory对象按照指定范围和指定分辨率转为热力矩阵。

示例

-- 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...
  • 本页导读 (1)
文档反馈