All Products
Search
Document Center

ApsaraDB RDS:ST_AsText

Last Updated:Mar 28, 2026

Converts a geographic grid object to its text representation in a specified encoding standard.

Syntax

-- Convert a GeomGrid scalar to text
text ST_AsText(geomgrid grid,
               integer precision DEFAULT -1,
               bool separated DEFAULT false,
               text standard DEFAULT 'GGER')

-- Convert a GeomGrid array to a text array
text[] ST_AsText(geomgrid[] grid,
                 integer precision DEFAULT -1,
                 bool separated DEFAULT false,
                 text standard DEFAULT 'GGER')

-- Convert an H3Grid to text
text ST_AsText(h3grid grid)

Parameters

ParameterTypeDefaultDescription
gridGeomGrid or H3GridThe geographic grid object to convert.
precisioninteger-1The precision level for the output. Valid values: 1 to 32. Set to -1 to use the precision stored in the grid.
separatedBooleanfalseSpecifies whether to use split encoding. Applies to 3D GeoSpatial Grid Encoding Rule (GGER) grids.
standardtext'GGER'The encoding standard. The only supported value is GGER (GeoSpatial Grid Encoding Rule), developed by the Ministry of Natural Resources of the People's Republic of China.

Description

ST_AsText encodes a geographic grid as text based on the precision level and encoding standard you specify.

Note: If the precision you specify is higher than the precision stored in the grid, the output is not zero-padded to fill the gap.

When split encoding is enabled (separated = true), the horizontal and height components are returned separately. The height encoding is the binary text code for the grid's index value in the height dimension:

  • If the grid is above the surface, the height encoding starts with +.

  • If the grid is below the surface, the height encoding starts with -.

Examples

Use the default precision level

WITH g AS (
  SELECT unnest(ST_AsGrid(
    ST_geomfromtext('POINT(116.31522216796875 39.910277777777778)', 4490), 15)) AS grid)
SELECT ST_AsText(grid) FROM g;
    st_astext
------------------
 G001310322230230

Specify an output precision level

WITH g AS (
  SELECT unnest(ST_AsGrid(
    ST_geomfromtext('POINT(116.31522216796875 39.910277777777778)', 4490), 15)) AS grid)
SELECT ST_AsText(grid, 8) FROM g;
  st_astext
-------------
 G00131032

3D encoding

SELECT unnest(ST_AsText(
  ST_As3DGrid('srid=4490;POINT(116.31522216796875 39.910277777777778 1001.8)'::geometry, 20)));
         unnest
------------------------
 GZ00262064446046072072

Split encoding

The horizontal and height components are returned as separate values. The + prefix on the height value indicates the grid is above the surface.

SELECT unnest(ST_AsText(
  ST_As3DGrid('srid=4490;POINT(116.31522216796875 39.910277777777778 1001.8)'::geometry, 20),
  -1, true));
              unnest
-------------------------------
 G00131032223023031031, +10010

H3 encoding

SELECT ST_AsText(ST_H3FromLatLng(20.5, 128.2, 8));
     st_astext
-----------------
 884a126689fffff

See also

  • ST_AsGrid — converts a geometry to a GeomGrid

  • ST_As3DGrid — converts a 3D geometry to a GeomGrid with height

  • ST_H3FromLatLng — creates an H3Grid from latitude and longitude coordinates