ST_AsGrid

更新时间:
复制 MD 格式

Returns an array of grids that intersect with a geometry.

Syntax

geomgrid[] ST_AsGrid(geometry geom, integer precision)

Parameters

ParameterDescription
geomThe geometry to query.
precisionThe precision level for the query. Valid values: 0 to 31.

Usage notes

The geometry must use the CGC2000 spatial reference system (SRID: 4490). If the geometry uses a different spatial reference system, ST_AsGrid calls ST_Transform to convert the coordinates to CGC2000 before processing.

The function returns a geomgrid[] array of geometry-represented grids. The following figure shows examples of grid intersections with a point, a line, and a polygon.

网格编码图

Examples

Query the grid that intersects with a point at precision level 15:

select st_astext(st_asgrid(
    ST_geomfromtext('POINT(116.31522216796875 39.910277777777778)',4490), 15))

Output:

     st_astext
--------------------
 {G001310322230230}

Query the grids that intersect with a line at precision level 18:

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

Output:

                  st_astext
--------------------------------------------------------------------------------
 {G001331032213300011,G001331032213300013,G001331032213122320,G001331032213122322,G001331032213300100,G001331032213122303,G001331032213122321,G001331032213122312}