All Products
Search
Document Center

ApsaraDB RDS:ST_AsMVT3D

Last Updated:Mar 28, 2026

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

ParameterTypeDefaultValid valuesDescription
rowanyelementThe row containing at least one 3D geometry column.
nametextDefaultThe name of the layer in the output tile.
extentinteger40962568192The number of tiles in screen space.
geom_nametextFirst geometry columnThe name of the geometry column in the row.
feature_id_nametextNULL or negative → ignoredThe name of the Feature ID column in the row. Set to NULL or a negative value to omit the Feature ID.

Usage notes

  • ST_AsMVT3D is an aggregate function. Use it with SELECT ... FROM on a derived table.

  • Call ST_AsMVTGeom3D to represent 3D geometries in the tile coordinate system and encode other columns as spatial features of non-geometric attributes.

  • Combine multiple layers with || or STRING_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) and LineTo3D(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.

image..png

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