ST_AsMeshGeom converts a geographic grid object (geomgrid) into its corresponding meshgeom spatial range, making the 3D grid cell available for spatial queries and text inspection.
Syntax
meshgeom ST_AsMeshGeom(geomgrid grid);
meshgeom[] ST_AsMeshGeom(geomgrid[] grid);Parameters
| Parameter | Type | Description |
|---|---|---|
grid | geomgrid or geomgrid[] | A geographic grid object typically generated by ST_As3DGrid. Pass an array to convert multiple grid cells in one call. |
Description
ST_AsMeshGeom returns the meshgeom-type spatial range of a geographic grid. The returned meshgeom value encodes the grid cell as an indexed 3D surface — a list of vertices and face indices — that defines the cell's spatial boundaries. This function is the bridge between grid generation and spatial analysis: call it after ST_As3DGrid to produce input for spatial queries, or pass the result to ST_AsText to inspect it in WKT format.
Examples
Convert a 3D grid cell to meshgeom
The following example generates a level-20 3D grid from a point, expands the resulting array with unnest, converts each cell to meshgeom, and returns the WKT representation.
SELECT ST_AsText(ST_AsMeshGeom(unnest(ST_As3DGrid(
'srid=4490;POINT(116.31522216796875 39.910277777777778 1001.8)'::geometry, 20))));Expected output:
st_astext
--------------------------------------------------------------------------------------------------------------
MESHGEOM(PATCH(INDEXSURFACE Z (VERTEX(116.315 39.91 970.027683307417,116.315 39.9105555555556 970.027683307417,
116.315555555556 39.9105555555556 970.027683307417,116.315555555556 39.91 970.027683307417,
116.315 39.91 1023.92243561707,116.315 39.9105555555556 1023.92243561707,
116.315555555556 39.9105555555556 1023.92243561707,116.315555555556 39.91 1023.92243561707),
INDEX((0,1,2,3),(4,7,6,5),(0,4,5,1),(3,2,6,7),(0,3,7,4),(1,5,6,2)))))The output structure breaks down as follows:
`VERTEX(...)` — lists the 8 corner coordinates of the grid cell as
(longitude latitude Z)pairs. The first four entries are the bottom face; the next four are the top face.`INDEX(...)` — defines the 6 faces of the cell using vertex indices (0-based). Each tuple references the vertices that form one face of the 3D box.
What's next
ST_As3DGrid— generatesgeomgridobjects from a geometry point and grid level, providing the input forST_AsMeshGeomST_AsText— converts ameshgeomvalue to its WKT string representation for inspection