Converts a heatmap tile to a 2D array for inspection and analysis.
Syntax
float8[][] ST_HMTAsArray(bytea hmt);Return value
Returns a 2D float8 array. Each element represents a statistical value of the corresponding cell in the heatmap grid.
Parameters
| Parameter | Type | Description |
|---|---|---|
hmt | bytea | The heatmap tile in protobuf binary format. Generate this value using ST_AsHMT. |
Description
ST_HMTAsArray takes a heatmap tile generated by ST_AsHMT and converts it to a 2D float8 array. The array preserves the spatial grid structure of the heatmap, making individual cell values accessible for programmatic processing or visual inspection.
Examples
The following example creates a test table with 10 geometry points, generates a heatmap tile over a 10×10 pixel grid, and converts it to a 2D 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), -- spatial extent
10, -- width in pixels
10 -- height in pixels
))
FROM test_table;Expected 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 output is a 10×10 array indexed [0:9][0:9]. The diagonal pattern of 1 values reflects that each of the 10 points falls in a distinct grid cell along the diagonal of the spatial extent.