All Products
Search
Document Center

PolarDB:ST_AsMVTGeom

Last Updated:Mar 28, 2026

Converts a geographic grid object (geomgrid or H3) into a geometry in the tile coordinate system, ready for use with ST_AsMVT to generate Mapbox Vector Tile (MVT) output.

Syntax

geometry ST_AsMVTGeom(geomgrid grid, geometry bounds, int4 extent, int4 buffer, boolean clip_geom);
geometry ST_AsMVTGeom(h3grid grid, geometry bounds, int4 extent, int4 buffer, boolean clip_geom);

Return value

Returns a geometric object in a coordinate system.

Parameters

ParameterDescriptionDefault
gridThe geomgrid or H3 geographic grid object to output to MVT.
boundsThe rectangular boundary of the tile, excluding the buffer. Must be a geometry type (not Box2D).
extentThe tile size in the tile coordinate system.4096
bufferThe buffer size in the tile coordinate system.256
clip_geomSpecifies whether to clip the geometry at the tile boundary.true

Usage notes

  • The bounds parameter determines the output coordinate system. Use ST_TileEnvelope to generate bounds — it sets the correct coordinate system automatically. If you generate bounds by another method, specify the Spatial Reference Identifier (SRID) explicitly.

  • Unlike the standard PostGIS ST_AsMVTGeom (which takes a geometry input), this variant accepts a geomgrid or h3grid as the first argument. The bounds parameter type is geometry, not Box2D.

Examples

Convert a geomgrid to tile geometry

Use ST_TileEnvelope to generate the tile boundary (SRID is set automatically):

SELECT st_asmvtgeom('010200040000'::geomgrid, st_tileenvelope(0, 0, 0));

Output:

0103000020110F000001000000050000000000000000D8A2400000000000FC99400000000000D8A240000000000000A040000000000000A040000000000000A040000000000000A0400000000000FC99400000000000D8A2400000000000FC9940

Pass a transformed tile envelope when working in SRID 4326:

SELECT st_asmvtgeom('010200040000'::geomgrid, st_transform(st_tileenvelope(0, 0, 0), 4326));

Output:

0103000020E610000001000000050000000000000000D8A2400000000000F493400000000000D8A240000000000000A040000000000000A040000000000000A040000000000000A0400000000000F493400000000000D8A2400000000000F49340

Override the default extent, buffer, and clipping behavior:

SELECT st_asmvtgeom('010200040000'::geomgrid, st_transform(st_tileenvelope(0, 0, 0), 4326), 1024, 128, false);

Output:

0103000020E610000001000000050000000000000000D882400000000000F073400000000000D8824000000000000080400000000000008040000000000000804000000000000080400000000000F073400000000000D882400000000000F07340

Convert an H3 grid cell to tile geometry

Use ST_TileEnvelope as the tile boundary:

SELECT st_asmvtgeom(st_h3fromlatlng(20.5, 128.2, 5), st_tileenvelope(0, 0, 0));

Output:

0103000020110F00000100000006000000000000000064AB400000000000449C40000000000066AB400000000000489C40000000000066AB4000000000004C9C40000000000062AB4000000000004C9C40000000000062AB400000000000489C40000000000064AB400000000000449C40

Specify the SRID explicitly when the bounds geometry is not generated by ST_TileEnvelope:

SELECT st_asmvtgeom(st_h3fromlatlng(20.5, 128.2, 5), 'SRID=4326;POLYGON((-180 -85,-180 85, 180 85, 180 -85, -180 -85))');

Output:

0103000020E61000000100000007000000000000000064AB400000000000449840000000000066AB400000000000489840000000000066AB400000000000509840000000000064AB400000000000549840000000000062AB400000000000549840000000000062AB4000000000004C9840000000000064AB40000000000044984