文档

ST_AsHMT

更新时间:

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

语法

bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, int4 value default 1, boolean point_mode default false);
bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, int4 value);
bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, int4 value, boolean point_mode);
bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, float8 value);
bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, float8 value, boolean point_mode);
bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, int4 value, cstring config);
bytea ST_AsHMT(geometry geometry_set, geometry extent, int4 width, int4 height, float8 value, cstring config);

返回值

返回一个基于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类型数组,按行方式进行组织。

  • 矩阵按照x递增、y递减的方式进行组织,可以方便地转换为图片格式。

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

参数

参数名称

描述

geometry_set

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

extent

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

width

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

height

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

value

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

point_mode

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

config

基于json表示的字符串,用于表示热力图的样式。

描述

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

如果数据的空间参考与传入的空间范围的空间参考不一致,会自动将数据的空间参考转换为传入的空间参考,并进行统计。

config为json字符串表示的计算方式,具体说明如下:

参数名称

描述

类型

默认值

说明

type

聚合的类型。

string

sum

取值如下:

  • sum

  • min

  • max

  • avg

point_mod

是否使用点模式。

boolean

false

-

说明

使用int4类型计算sum时可能会由于INT32的限制(-2147483648到2147483647)无法获得正确的返回值,建议使用float8类型。

示例

-- create table
CREATE TABLE test_table AS
SELECT i num,
    ST_SetSrid(st_makepoint((i-0.5)::numeric, (i-0.5)::numeric), 4326) geom,
    i*100::int4 weight,
    i*i*i::float8 volume
FROM generate_series(1, 10) i;

-- count quantity
SELECT ST_AsHMT(geom, --geometry type
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    1024,        -- Width, in pixel
    800        -- height
)
FROM test_table;

---------
\x080010a0061880083284...

-- count value
SELECT ST_AsHMT(geom, --geometry type
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    1024,        -- Width
    800,       -- height
    weight     -- value column
)
FROM test_table;
---------
\x080010a0061880...

-- complex count
SELECT ST_AsHMT(geom, --geometry type
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    1024,        -- Width
    800,        -- height
    weight / volume * 1.2     -- complex value
)
FROM test_table;
---------
\x080110a0061880083a85...

-- point mode
SELECT ST_AsHMT(geom, --geometry type
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    1024,        -- Width, in pixel
    800,        -- height,
    1::integer,  -- value
    true        -- point mode
)
FROM test_table;
---------
\x080010a0061880083...

-- where clause
SELECT ST_AsHMT(geom, --geometry type
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    1024,        -- Width, in pixel
    800        -- height
)
FROM test_table
WHERE num <5;
---------
\x080010a00618...

-- average 
SELECT ST_AsHMT(the_geom,
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    256,        -- Width, in pixel
    256        -- height
    weight, 
    '{"type":"avg"}'::cstring)
FROM test_table;
---------
\x080010a00618...

-- Use min, point mode 
SELECT ST_AsHMT(the_geom,
    ST_MakeEnvelope(0, 0, 10, 10, 4326), -- Extent
    256,        -- Width, in pixel
    256        -- height
    weight, 
    '{"type":"min", "point_mode":true}'::cstring)
FROM test_table;
---------
\x080010a00618...

  • 本页导读 (0)
文档反馈