Converts a 3D geometry into an array of geographic grids that intersect with it.
Syntax
geomgrid[] ST_As3DGrid(geometry geom3d, integer precision, bool degenerated default false);
geomgrid[] ST_As3DGrid(meshgeom geom3d, integer precision, bool degenerated default false);
geomgrid[] ST_As3DGrid(sfmesh geom3d, integer precision, bool degenerated default false);
geomgrid[] ST_As3DGrid(vomesh geom3d, integer precision, bool degenerated default false);Parameters
| Parameter | Description |
|---|---|
| geom3d | The input 3D geometry. Accepted types: geometry, meshgeom, sfmesh, vomesh. |
| precision | The precision level of the geographic grid. Valid values: 1–32. |
| degenerated | Specifies whether to include degenerated grids. false (default): returns only non-degenerated grids. true: includes degenerated grids. |
Usage notes
The input geometry must use the CGC2000 spatial reference system, with a spatial reference system identifier (SRID) of 4490. If your geometry uses a different spatial reference system, make sure its coordinates can be converted to CGC2000 coordinates before calling this function.
The function returns an array of geomgrid values representing all geographic grids that intersect with the input geometry. The following images show an example of this intersection:


Examples
Convert a 3D line segment (geometry type)
This example converts a 3D LINESTRING at precision level 10 and returns the grids it intersects.
SELECT ST_AsText(ST_As3DGrid(
'srid=4490;LINESTRING Z (116 39 2000,116.012 39.009 3000)'::geometry, 10));Output:
st_astext
-------------------------------------------------------
{GZ0026204626,GZ0026204662,GZ0026206404,GZ0026206440}Convert a closed solid (meshgeom type)
This example converts a solid mesh geometry defined by indexed surfaces at precision level 10.
SELECT ST_AsText(ST_As3DGrid(st_meshgeomfromtext('srid=4490;SOLID=TRUE;MESHGEOM(PATCH(INDEXSURFACE Z (VERTEX(115.966 38.9757000000001 3000,
116 38.9757000000001 3000,116 38.9999999999999 3000,115.966 38.9999999999999 3000,116 38.9999999999999 0,
116 38.9757000000001 0,115.966 38.9757000000001 0,115.966 38.9999999999999 0),
INDEX((0,1,2),(2,3,0),(4,5,6),(6,7,4),(3,7,6),(6,0,3),(0,6,5),(5,1,0),(1,5,4),(4,2,1),(2,4,7),(7,3,2)))))'),10));Output:
st_astext
-------------------------------------------------------
{GZ0026204626,GZ0026206404,GZ4026204626,GZ4026206404}Convert a scene mesh with a transform matrix (sfmesh type)
This example uses a JSON-format scene mesh (sfmesh) at precision level 8 with degenerated=true to include degenerated grids.
SELECT ST_AsText(ST_As3DGrid(st_meshfromtext(
'{"version" : 1, "srid" : 4490, "root" : 0,
"meshgeoms" : ["MESHGEOM(PATCH(POLYGON Z ((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0))))"],
"primitives" : [{"meshgeom" : 0}], "nodes" : [{"primitive" : 0,"matrix" : [0.012,0,0,116,0,0.009,0,39,0,0,1000,0,0,0,0,1]}]}'),8,true));Output:
st_astext
-----------------------------------------------
{GZ00262046,GZ00262064,GZ40262046,GZ40262064}Convert a volumetric mesh (vomesh type)
This example converts a VOMESH geometry with Level of Detail (LOD) 2 at precision level 15 with degenerated=true.
SELECT ST_AsText(ST_As3DGrid(ST_VOMeshFromText(
'SRID=4490;LOD=2;VOMESH(VERTEX(COORDS(116.012 39 0,116 39.009 0,115.988 39 0,116 38.991 0,116 39 1000)),
FACE(INDEX((0,1,2,3),(1,0,4),(2,1,4),(3,2,4),(0,3,4))),
CELL(INDEX((0,1,2,3,4)),DIRECTION((0,1,1,1,0))))'),15, true));Output:
st_astext
---------------------------------------------------------------------------------------
------------------------------------------------------------
{GZ002620462666066,GZ002620466222022,GZ002620640444044,GZ002620644000000,GZ402620462666066,
GZ402620466222022,GZ402620640444044,GZ402620644000000}What's next
ST_AsText: Convert a geometry value to its Well-Known Text (WKT) representation.
st_meshgeomfromtext: Create a
meshgeomfrom a text representation.st_meshfromtext: Create an
sfmeshfrom a JSON text representation.ST_VOMeshFromText: Create a
vomeshfrom a text representation.