Encodes rows containing 3D geometry into the Mapbox Vector Tile (MVT) binary format. Use ST_AsMVT3D together with ST_AsMVTGeom3D to build 3D vector tiles from spatial data in PolarDB for PostgreSQL.
Syntax
bytea ST_AsMVT3D(anyelement set row)
bytea ST_AsMVT3D(anyelement row, text name)
bytea ST_AsMVT3D(anyelement row, text name, integer extent)
bytea ST_AsMVT3D(anyelement row, text name, integer extent, text geom_name)
bytea ST_AsMVT3D(anyelement row, text name, integer extent, text geom_name, text feature_id_name)Parameters
| Parameter | Description | Default |
|---|---|---|
row | A row that contains at least one 3D geometry column. The geometry column is encoded as a spatial feature; other columns are encoded as non-geometric attributes. | — |
name | The name of the tile layer. | Default |
extent | The tile resolution in screen space (tile units). Valid values: 256–8192. | 4096 |
geom_name | The name of the geometry column to encode. If omitted, the first geometry column in the row is used. | First geometry column |
feature_id_name | The name of the Feature ID column. If set to NULL or a negative value, no Feature ID is set. | NULL |
Description
ST_AsMVT3D is an aggregate function that returns a bytea value containing the binary MVT tile data. It extends standard MVT encoding with 3D geometry support.
Workflow: call ST_AsMVTGeom3D first to project 3D geometries into the tile coordinate system, then pass the result to ST_AsMVT3D to produce the final tile.
Multi-layer tiles: combine multiple calls with || or STRING_AGG to produce a tile with multiple layers:
SELECT ST_AsMVT3D(layer_a.*) || ST_AsMVT3D(layer_b.*) AS tile;Z-axis encoding
3D geometry is encoded on the z-axis using two mechanisms:
CommandID encoding — uses the extended command set
MoveTo3D(5)andLineTo3D(6)with interleaved XYZ coordinate sequences.Numeric quantization — z values are mapped to integers using the formula
numeric value = 7 × (z + 450). Valid elevation range: −450 to 8848 meters.
For details on the MVT binary encoding format, see the vector-tile-spec.
The following figure shows a large-scale 3D scenario rendered using 3D MVT tile technology.

Example
The following query encodes a MULTIPOLYGON geometry into a 3D MVT tile. ST_Transform reprojects from EPSG:4326 to EPSG:3857 (Web Mercator), and ST_TileEnvelope defines the tile boundary.
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;Output:
\x1a760a0764656661756c74125812020000180322500d8044a842b83116ff23d80105802400080f0d810481041d162e000e2e590e0f0dd920dc0405168024d70106c727f3160d0f0dc827f4160e1600f31615c72700080f0d0000001600cc1808c80300000f1a046e616d6522060a04746573742880207802See also
ST_AsMVTGeom3D — projects 3D geometries into the tile coordinate system required by
ST_AsMVT3DMapbox Vector Tile specification — the underlying tile format specification