An aggregate function that serializes rows of 3D MVT geometry into a Mapbox Vector Tile (MVT) binary tile. It extends the standard MVT format with z-axis (elevation) support, enabling 3D vector tile generation directly in PostgreSQL.
Syntax
-- Syntax 1: minimal form
bytea ST_AsMVT3D(anyelement set row)
-- Syntax 2: specify layer name
bytea ST_AsMVT3D(anyelement row, text name)
-- Syntax 3: specify layer name and tile extent
bytea ST_AsMVT3D(anyelement row, text name, integer extent)
-- Syntax 4: specify layer name, tile extent, and geometry column
bytea ST_AsMVT3D(anyelement row, text name, integer extent, text geom_name)
-- Syntax 5: full form with Feature ID
bytea ST_AsMVT3D(anyelement row, text name, integer extent, text geom_name, text feature_id_name)Parameters
| Parameter | Type | Default | Valid values | Description |
|---|---|---|---|---|
row | anyelement | — | — | The row containing at least one 3D geometry column. |
name | text | Default | — | The name of the layer in the output tile. |
extent | integer | 4096 | 256–8192 | The number of tiles in screen space. |
geom_name | text | First geometry column | — | The name of the geometry column in the row. |
feature_id_name | text | — | NULL or negative → ignored | The name of the Feature ID column in the row. Set to NULL or a negative value to omit the Feature ID. |
Usage notes
ST_AsMVT3Dis an aggregate function. Use it withSELECT ... FROMon a derived table.Call
ST_AsMVTGeom3Dto represent 3D geometries in the tile coordinate system and encode other columns as spatial features of non-geometric attributes.Combine multiple layers with
||orSTRING_AGG:SELECT ST_AsMVT3D(layer1.*) || ST_AsMVT3D(layer2.*) AS tile;
Z-axis encoding
ST_AsMVT3D extends the MVT command set to encode elevation:
CommandID encoding: uses
MoveTo3D(5)andLineTo3D(6)to encode XYZ coordinate sequences.Z-axis quantization:
Numeric value = 7 × (z + 450), with valid elevation range −450 to 8848.
For the full specification, see vector-tile-spec.
The following image shows a large-scale 3D scenario rendered using 3D MVT tile technology.

Example
The following query generates a 3D MVT tile. ST_AsMVTGeom3D prepares the 3D geometries into tile coordinates; ST_AsMVT3D then serializes the result into a binary tile.
WITH mvtgeom AS (
SELECT
ST_AsMVTGeom3D(
ST_Transform('SRID=4326; MULTIPOLYGON(((100 50 0, -100 50 1, -100 -50 2, 100 -50 3, 100 50 0)), ((0 0 0, 1 0 1, 2 2 2, 0 0 0)))'::geometry, 3857),
ST_TileEnvelope(1, 0, 0)
) AS geom,
'test' AS name
)
SELECT ST_AsMVT3D(mvtgeom.*) FROM mvtgeom;Expected output (binary MVT in hex):
st_asmvt3d
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
\x1a760a0764656661756c74125812020000180322500d8044a842b83116ff23d80105802400080f0d810481041d162e000e2e590e0f0dd920dc0405168024d70106c727f3160d0f0dc827f4160e1600f31615c72700080f0d0000001600cc1808c80300000f1a046e616d6522060a04746573742880207802
(1 row)Related topics
ST_AsMVTGeom3D — prepare 3D geometries for use with
ST_AsMVT3D