All Products
Search
Document Center

PolarDB:ST_Level

Last Updated:Mar 28, 2026

Returns the gridding level of a geographic grid.

Syntax

integer ST_Level(geomgrid gridcode);
integer[] ST_Level(geomgrid[] gridcode);
integer ST_Level(h3grid gridcode);

Parameters

ParameterDescription
gridcodeThe geographic grid object. Accepts a single geomgrid, an array of geomgrid objects (geomgrid[]), or a single h3grid.

Description

ST_Level returns the level of a geographic grid object. The return type depends on the input:

  • Single `geomgrid`: returns an integer representing the grid level.

  • `geomgrid[]` array: returns an integer[] array representing the level range across all grids in the array.

  • Single `h3grid`: returns an integer representing the H3 resolution level.

Examples

Get the level of a single geomgrid

SELECT st_level(ST_GridFromText('GZ0026206440'));
 st_level
----------
       10

Get the level range of a geomgrid array

SELECT st_level(st_as3dgrid('srid=4490;GEOMETRYCOLLECTION Z (MULTIPOLYGON Z (((116 39 5000,116.12 39 5000,116.12 39.09 5000,116 39.09 5000,116 39 5000),
(116.024 39.018 5000,116.024 39.045 5000,116.06 39.045 5000,116.06 39.018 5000,116.024 39.018 5000))),
POINT Z (116 39 5000),MULTILINESTRING Z ((116 39 5000,116.024 39 5000),(116.012 39.009 5000,116.024 39.018 5000)),
POLYHEDRALSURFACE Z (((116 39 0,116 39 1000,116 39.009 0,116 39 0)),((116 39 0,116 39.009 0,116.012 39 0,116 39 0)),
((116 39 0,116.012 39 0,116 39 1000,116 39 0)),((116.012 39 0,116 39.009 0,116 39 1000,116.012 39 0))))'::geometry,
20,true));
 st_level
----------
 {19,20}

Get the level of an H3 grid

-- H3 encoding
SELECT st_level(st_h3frombinary('\x010100ffff9f6826a18408'));
 st_level
----------
        8

See also

FunctionDescription
ST_GridFromTextCreates a geomgrid object from a grid code string
st_as3dgridConverts a 3D geometry to a geomgrid array
st_h3frombinaryCreates an h3grid object from a binary H3 index