All Products
Search
Document Center

PolarDB:ST_AsGrid

Last Updated:Oct 13, 2023

This topic describes the ST_AsGrid function. This function queries the grid objects that intersect with a geometry.

Syntax

geomgrid[] ST_AsGrid(geometry geom, integer precision, bool degenerated default false);

Parameters

Parameter

Description

geom

The geometry that you want to query.

precision

The precision level. Valid values: 1 to 32. A larger value indicates a more accurate query result.

degenerated

Specifies whether to use a degenerated grid.

The following figures compare a degenerated grid and a standard grid.退化网格

Description

The geometry must use the CGC2000 spatial reference system. In addition, the spatial reference system identifier (SRID) of the geometry must be 4490. If the geometry does not use the CGC2000 spatial reference system, the ST_Transform function is invoked to convert the coordinates of the geometry into CGC2000 coordinates.

This function returns an array consisting of geographic grids that intersect with the geometry. The following figure provides an example on how geographic grids intersect with a point, a line, and a polygon.

网格编码图

Examples

select st_astext(st_asgrid(
    ST_geomfromtext('POINT(116.31522216796875 39.910277777777778)',4490), 15));
    
     st_astext      
--------------------
 {G001310322230230}

select st_astext(st_asgrid(
    ST_geomfromtext('LINESTRING(122.48077 51.72814,122.47416 51.73714)',4490), 18));

                  st_astext                                                                          
--------------------------------------------------------------------------------
 {G001331032213300011,G001331032213300013,G001331032213122320,G00133103221312232
2,G001331032213300100,G001331032213122303,G001331032213122321,G00133103221312231
2}

select st_astext(st_asgrid(
  ST_geomfromtext('POLYGON((-0.08077 -0.02814, 0.0482 -0.03, 0.07426 0.03724, -0.08077 -0.02814))',4490),15));

                          st_astext
--------------------------------------------------------------------------------
 {G000000000000000,G000000000000001,G000000000000003,G000000000000010,G000000000
000011,G000000000000012,G000000000000013,G000000000000031,G000000000000102,G0000
00000000120,G100000000000000,G200000000000000,G200000000000001,G200000000000002,
G200000000000003,G200000000000010,G200000000000011,G200000000000012,G20000000000
0013,G300000000000000,G300000000000001,G300000000000002,G300000000000003,G300000
000000010,G300000000000011,G300000000000012,G300000000000013,G300000000000102}

select st_astext(st_asgrid(
  ST_geomfromtext('POLYGON((-0.08077 -0.02814, 0.0482 -0.03, 0.07426 0.03724, -0.08077 -0.02814))',4490),15,true));

                         st_astext
--------------------------------------------------------------------------------
 {G000000000000000,G000000000000001,G000000000000003,G00000000000001,G0000000000
00031,G000000000000102,G000000000000120,G100000000000000,G20000000000000,G200000
00000001,G30000000000000,G30000000000001,G300000000000102}