All Products
Search
Document Center

ApsaraDB RDS:ST_AsText

Last Updated:Sep 28, 2023

This topic describes the ST_AsText function. This function converts a geographic grid into text that is encoded in a specified specification.

Syntax

text ST_AsText(geomgrid    grid
integer precision default -1,
bool separated default false,
text standard default 'GGER')

text[] ST_AsText(geomgrid[]    grid
integer precision default -1,
bool separated default false,
text standard default 'GGER')

text ST_AsText(h3grid  grid)

Parameters

Parameter

Description

grid

The geographical grid object that you want to obtain. The data type is GeomGrid or H3Grid.

precision

The precision level. Valid values: 1 to 32. The value -1 indicates that the precision level of the geographic grid is used.

separated

Specifies whether to use split encoding. This parameter is suitable for 3D GeoSpatial Grid Encoding Rule (GGER).

standard

The specification standard: GGER. It is developed by the Ministry of Natural Resources of the People's Republic of China. Default value: GGER.

Description

The function converts a geographic grid to text based on the specified layer, precision, and encoding specification. If the specified precision is higher than the storage precision of the geographic grid, the system does not fill zeros for the output. In split encoding, the height encoding indicates that a grid is encoded as the binary text code for the index value of the grid in the height dimension. If a grid is above the surface, the height encoding of the grid starts with a plus sign (+). If a grid is under the surface, the height encoding of the grid starts with a hyphen (-).

Examples

-- Use the default layer.
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 the output layer.
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 is used.
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