All Products
Search
Document Center

ApsaraDB RDS:ST_Level

Last Updated:Mar 27, 2026

Returns the gridding level of a geographic grid. For an array of geographic grids, returns the level range as an integer array.

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 values, or an h3grid object.

Return value

Input typeReturn typeDescription
geomgridintegerThe level of the geographic grid.
geomgrid[]integer[]The level range across all grids in the array.
h3gridintegerThe level of the H3 grid.

Examples

Get the level of a single geographic grid

SELECT st_level(ST_GridFromText('GZ0026206440'));

Result:

 st_level
----------
       10

Get the level range of a 3D grid array

The following example uses st_as3dgrid to generate a grid array from a geometry collection with SRID 4490, then returns the level range.

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));

Result:

 st_level
----------
 {19,20}

Get the level of an H3 grid

SELECT st_level(st_h3frombinary('\x010100ffff9f6826a18408'));

Result:

 st_level
----------
        8