All Products
Search
Document Center

:ST_AsHMT

Last Updated:Feb 29, 2024

Converts a set of trajectory objects into heat map tiles (Heat Map Tile) based on a specified range and a specified resolution.

Syntax

bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, int4 value default 1, boolean point_mode default false);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, int4 value);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, int4 value, boolean point_mode);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, float8 value);
bytea ST_AsHMT(trajectory trajectory_set, geometry extent, int4 width, int4 height, float8 value, boolean point_mode);

Return value

Returns a Protobuf-based binary data structure that represents the value of each point in the grid. See the following sample Protobuf file:

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;
    }
}
Note
  • The Type value is specified by the input parameters, and can be int32 or double. The int32 type is used to calculate information such as quantity, and the double type is used to calculate information such as metrics.

  • The value of rows represents the number of rows of the matrix, and the value of columns represents the number of columns of the grid.

  • The values in the matrix are arrays of the type that is specified by Type and are organized by row.

  • You can use the ST_HMTAsArray function to convert the returned value into arrays.

Parameters

Parameter

Description

geometry_set

The geometry column field used by the aggregate function.

extent

The geographic range to be obtained. Only the bounding box is obtained. This parameter can be used in conjunction with the ST_TileEnvelope function.

width

The width of the grid, which corresponds to the columns of the results.

height

The height of the grid, which corresponds to the rows of the result.

value

The values to be calculated. The sum of specified values are calculated.

point_mode

Whether to enable the point mode. If you use the point mode, only the values of the points in the grid are calculated.

Description

Converts a set of trajectory objects into heat map tiles based on a specified range and a specified resolution.

Example

-- create table
CREATE test_table AS
SELECT i as num, 
               st_maketrajectory('STPOINT'::leaftype, 
                    st_MakeLine(ST_Point(i::numeric/10, i::numeric/10), ST_Point((i+10)::numeric/10, (i+10)::numeric/10)), 
                    '[2010-01-01 14:30, 2010-01-01 15:30)'::tsrange, NULL) as traj,
    i*100::int4 weight,
    i*i*i::float8 volume
FROM generate_series(1, 100) i;

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

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

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

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

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

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