All Products
Search
Document Center

ApsaraDB RDS:ST_HMTStats

Last Updated:Mar 28, 2026

Computes statistics on a heatmap tile for use during map rendering.

Syntax

record ST_HMTStats(bytea hmt, integer factor default 1, out float8 min, out float8 max, out float8 mean, out float8 sum, out float8 count, out float8 std, out float8 median, out float8 mode, out float8[] percentile);

Parameters

ParameterTypeDefaultDescription
hmtbyteaThe heatmap tile binary encoded in protobuf format. Generate this value using ST_AsHMT.
factorinteger1The sampling interval. A value of n means one in every n values is included in each statistical calculation. For example, factor=4 samples every fourth value, reducing the count from 100 to 25.

Return values

Returns a record with the following output fields:

FieldTypeDescription
minfloat8The minimum value.
maxfloat8The maximum value.
meanfloat8The average value.
sumfloat8The sum of all sampled values.
countfloat8The number of values included in the calculation.
stdfloat8The standard deviation.
medianfloat8The median value.
modefloat8The mode (most frequent value).
percentilefloat8[]An array of 100 percentile values.

Examples

The following examples use the same test table. Create it once, then run either query.

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;

Example 1: Default sampling (factor=1)

All 100 tile values are included in the calculation.

SELECT (ST_HMTstats(ST_AsHMT(the_geom,
    ST_MakeEnvelope(0, 0, 10, 10),
    10,
    10))).*
FROM test_table;

Expected output:

 min | max | mean | sum | count |        std         | median | mode |                  percentile
-----+-----+------+-----+-------+--------------------+--------+------+------------------------------------------------
   0 |   2 | 0.19 |  19 |   100 | 0.5778408085277467 |      0 |    0 | {0,0,...,0,0,1,2,2,2,2,2,2,2,2}

Example 2: Sparse sampling (factor=4)

Every fourth value is sampled, reducing the count to 25.

SELECT (ST_HMTstats(ST_AsHMT(the_geom,
    ST_MakeEnvelope(0, 0, 10, 10),
    10,
    10), 4)).*
FROM test_table;

Expected output:

 min | max | mean | sum | count |        std         | median | mode |                  percentile
-----+-----+------+-----+-------+--------------------+--------+------+------------------------------------------------
   0 |   2 | 0.16 |   4 |    25 | 0.5425863986500215 |      0 |    0 | {0,0,...,0,0,2,2,2,2,2,2,2}