All Products
Search
Document Center

PolarDB:ST_AsMVT3D

Last Updated:Mar 28, 2026

ST_AsMVT3D is an aggregate function that encodes rows containing 3D geometry into a Mapbox Vector Tile (MVT) binary. It returns a bytea value representing one MVT layer.

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

ParameterTypeDescriptionDefault
rowanyelementA row that contains at least one 3D geometry column.
nametextThe name of the MVT layer.Default
extentintegerThe tile resolution in screen-space units. Valid values: 256–8192.4096
geom_nametextThe name of the geometry column in the row.Name of the first geometry column
feature_id_nametextThe name of the feature ID column. Set to NULL or a negative value to omit the feature ID.

How it works

Generating a 3D MVT tile requires two functions in sequence:

  1. ST_AsMVTGeom3D — clips 3D geometries to the tile boundary, transforms coordinates to tile space, and quantizes them. Call this first.

  2. ST_AsMVT3D — takes the prepared rows and encodes them into the MVT binary format. Call this as the aggregate step.

A typical query follows this pattern:

WITH mvtgeom AS (
  SELECT ST_AsMVTGeom3D(geom, ST_TileEnvelope(z, x, y)) AS geom,
         name, category
  FROM   my_3d_features
  WHERE  geom && ST_TileEnvelope(z, x, y)
)
SELECT ST_AsMVT3D(mvtgeom.*)
FROM   mvtgeom;

To combine multiple layers into a single tile, use || or STRING_AGG:

SELECT ST_AsMVT3D(a.*) || ST_AsMVT3D(b.*) AS tile
FROM   layer_a a, layer_b b;

Z-axis encoding

ST_AsMVT3D extends the standard MVT specification with 3D support using the following encoding rules:

  • CommandID encoding: 3D geometries use MoveTo3D (command ID 5) and LineTo3D (command ID 6) with interleaved XYZXYZ... coordinate sequences.

  • Z-axis quantization formula: encoded_z = 7 × (z + 450). The valid z range is –450 to 8848 (meters), covering sea floor to the summit of Mount Everest.

For the full specification, see vector-tile-spec.

The following figure shows a large-scale 3D scenario rendered using 3D MVT tile technology.

image..png

Example

The following example converts a 3D MULTIPOLYGON in WGS 84 (SRID 4326) to tile coordinates, then encodes it as an MVT layer named buildings at zoom level 1, tile (0, 0).

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,
         'main_building' AS name
)
SELECT ST_AsMVT3D(mvtgeom.*, 'buildings') FROM mvtgeom;

The function returns a bytea value containing the encoded MVT tile data.

See also

  • ST_AsMVTGeom3D — prepares 3D geometries for use with ST_AsMVT3D

  • ST_TileEnvelope — generates a tile bounding box from zoom level and tile coordinates