Converts a heatmap tile to a 2D array for inspection and post-processing.
Syntax
float8[][] ST_HMTAsArray(bytea hmt);Parameters
| Parameter | Description |
|---|---|
hmt | The heatmap tile binary encoded in protobuf format. Generate this value using ST_AsHMT. |
Return value
Returns a float8[][] two-dimensional array. Each element represents a statistical value of the corresponding cell in the heatmap tile.
Example
The following example creates a test table with 10 points arranged diagonally, generates a heatmap tile over a 10×10 pixel extent, and converts it to an array.
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 column
ST_MakeEnvelope(0, 0, 10, 10, 4326), -- extent
10, -- width in pixels
10 -- height in pixels
))
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 result is a 10×10 array with values along the diagonal, reflecting the one-point-per-cell distribution of the input geometry.