All Products
Search
Document Center

PolarDB:ST_AsH3Grid

Last Updated:Mar 28, 2026

ST_AsH3Grid converts a 2D geometry object into an array of H3 grid cells that cover the geometry. The function accepts any coordinate reference system and automatically reprojects the geometry before computing the grid coverage.

Syntax

h3grid[] ST_AsH3Grid(geometry geom, integer precision, bool degenerated default false);

Parameters

ParameterTypeDescription
geomgeometryThe input 2D geometry object. Supported types include POINT, LINESTRING, MULTIPOLYGON, and other standard geometry types.
precisionintegerThe H3 grid resolution level. Valid values: 0 (coarsest) to 15 (finest).
degeneratedboolSpecifies whether to use a degenerated grid. Default: false.

Usage notes

Return type: The function returns h3grid[], an array of H3 grid cells. Each element represents one H3 cell that intersects or covers the input geometry.

SRID handling: The input geometry can use any coordinate reference system. The function reprojects it automatically before computing the H3 grid coverage.

Degenerated cells: When degenerated is set to true, degenerated grids work in the same way as H3.

Cell inclusion: For POINT geometries, the result is a single-element array — the one H3 cell that contains the point. For line and polygon geometries, the result is an array of all H3 cells that intersect the geometry.

Examples

POINT

SELECT ST_AsH3Grid(ST_GeomFromText('POINT(2932234 234234)', 28992), 4);

Output:

{010101FFFFFFFF09D54208}

LINESTRING

SELECT ST_AsH3Grid('SRID=4326;LINESTRING(122.48077 51.72814, 122.47416 51.73714)'::geometry, 10);

Output:

{010100FFFF59698658A108,010100FF7F58698658A108,010100FFFF5A698658A108,
 010100FF7F51698658A108,010100FF7F50698658A108,010100FF7F52698658A108,
 010100FF7FCD698658A108,010100FF7FCF698658A108,010100FF7FCE698658A108,
 010100FFFFC0698658A108,010100FF7FC7698658A108,010100FFFFD5698658A108}

12 cells cover the line at resolution 10.

MULTIPOLYGON

SELECT ST_AsH3Grid(
  'SRID=4326;MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2)))'::geometry,
  2
);

Output:

{010100FFFFFFFF7F882508,010100FFFFFFFF7F2C2808,010100FFFFFFFF7F2D2808,
 010100FFFFFFFF7F8B2508,010100FFFFFFFF7F2F2808,010100FFFFFFFF7F8D2508,
 010100FFFFFFFF7F892508,010100FFFFFFFF7F8F2508,010100FFFFFFFF7F542708,
 010100FFFFFFFF7F572708,010100FFFFFFFFFF882508,010100FFFFFFFFFF892508,
 010100FFFFFFFFFF2D2808,010100FFFFFFFFFF2E2808,010100FFFFFFFFFF8A2508,
 010100FFFFFFFFFF5708}

16 cells cover the multi-polygon at resolution 2.