All Products
Search
Document Center

PolarDB:ST_HMTAsArray

Last Updated:Mar 28, 2026

ST_HMTAsArray converts a heatmap tile (HMT) into a 2D float8 array, making the pixel values directly readable in a SQL result set.

Syntax

float8[][] ST_HMTAsArray(bytea hmt);

Parameters

ParameterTypeDescription
hmtbyteaA heatmap tile binary encoded in protobuf format. Typically generated by ST_AsHMT.

Return value

Returns a float8[][] two-dimensional array. Each element represents a statistical value of the corresponding pixel in the heatmap.

Example

The following example creates a test table with 10 point geometries, generates a heatmap tile with ST_AsHMT, and then converts the tile to a 2D array with ST_HMTAsArray.

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;

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

Output:

[0:9][0:9]={{1,0,0,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,0,0,0},{0,0,1,0,0,0,0,0,0,0},{0,0,0,1,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,0,0},{0,0,0,0,0,1,0,0,0,0},{0,0,0,0,0,0,1,0,0,0},{0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,0,0,0,1,0},{0,0,0,0,0,0,0,0,0,1}}

The prefix [0:9][0:9]= is PostgreSQL's notation for a two-dimensional array with explicit subscript bounds. Both dimensions run from index 0 to 9, corresponding to the 10x10 pixel grid. The diagonal pattern of 1 values reflects the 10 input points distributed evenly across the grid.

See also

  • ST_AsHMT — generates the heatmap tile binary (bytea) that this function consumes.