All Products
Search
Document Center

ApsaraDB RDS:ST_AsMVTGeom3D

Last Updated:Mar 28, 2026

Transforms a 3D geometry into the tile coordinate system required by ST_AsMVT3D to generate Mapbox Vector Tile (MVT) output. This function extends ST_AsMVTGeom with z-axis support, preserving z-coordinate values during the coordinate transformation.

Syntax

geometry ST_AsMVTGeom3D(
  geometry geom,
  box2d bounds,
  integer extent = 4096,
  integer buffer = 256,
  boolean clip_geom = true
);

Parameters

ParameterTypeDescriptionDefaultValid values
geomgeometryThe 3D geometry object to transform.
boundsbox2dThe rectangular boundaries of the tile in the target coordinate reference system (CRS), excluding the buffer. Use ST_TileEnvelope to generate this value.
extentintegerThe tile size in tile coordinate space, as defined by the MVT specification.4096256–8192
bufferintegerThe buffer size in tile coordinate space for geometry clipping.2561–4096
clip_geombooleanSpecifies whether to clip the 3D geometry to tile boundaries.true

Description

ST_AsMVTGeom3D prepares 3D geometry for use with ST_AsMVT3D. It transforms geometry coordinates into tile space and clips geometries to tile boundaries when clip_geom is true.

Key behaviors:

  • Transforms z-axis data along with x and y coordinates, preserving the full 3D geometry through the tile conversion process.

  • Requires tile boundaries in the same CRS as the input geometry so the geometry can be correctly transformed and clipped. Use ST_TileEnvelope to generate boundaries.

  • Does not support 3D polygon objects that contain interior rings.

Examples

Transform a 3D line string into tile coordinate space

The following example transforms a 3D line string from SRID 4326 to Web Mercator (SRID 3857) and converts it into tile coordinate space for tile (1, 0, 0).

SELECT ST_AsText(
  ST_AsMVTGeom3D(
    ST_Transform('SRID=4326; LINESTRING(-10 -10 30, -10 -20 30)'::geometry, 3857),
    ST_TileEnvelope(1, 0, 0)
  )
) AS geom;

Expected output:

                                        geom
------------------------------------------------------------------------------------
 MULTILINESTRING Z ((3868.44444444444 4324.7197219642 30,3868.44444444444 4352 30))
(1 row)

Generate a 3D MVT tile using ST_AsMVT3D

The following example shows a complete tile-generation query using a CTE. It transforms geometries from a table into tile coordinate space and aggregates them into binary MVT format for tile (12, 513, 412).

WITH mvtgeom AS (
  SELECT ST_AsMVTGeom3D(
    ST_Transform(geom, 3857),
    ST_TileEnvelope(12, 513, 412),
    extent => 4096,
    buffer => 256
  ) AS geom
  FROM your_3d_table
  WHERE geom && ST_Transform(ST_TileEnvelope(12, 513, 412), 4326)
)
SELECT ST_AsMVT3D(mvtgeom.*)
FROM mvtgeom;

Replace your_3d_table with the name of your table containing 3D geometry data.

See also