All Products
Search
Document Center

PolarDB:ST_AsMVTGeomEx

Last Updated:Mar 28, 2026

Transforms a geometry into the coordinate space of a Mapbox Vector Tile (MVT) tile, with pixel-level filtering to reduce frontend and backend load.

ST_AsMVTGeomEx extends ST_AsMVTGeom with an additional res_prec parameter. Use res_prec to filter out geometry objects that occupy fewer pixels than the threshold — reducing the number of vectors sent to the client and improving visualization performance.

Syntax

GEOMETRY ST_AsMVTGeomEx(
    GEOMETRY geom,
    BOX2D bounds,
    INTEGER res_prec=1,
    INTEGER extent=4096,
    INTEGER buffer=256,
    BOOLEAN clip_geom=true
);

Parameters

geom is the geometry object to transform into MVT tile coordinates.

bounds is the rectangular bounding box of the tile in map coordinate space, excluding the buffer.

res_prec controls the pixel-size filter. In a tile, if the maximum number of pixels a geometry occupies along either the x-axis or the y-axis is less than res_prec, that geometry is filtered out and not included in the output.

extent is the tile size in the tile coordinate system. Defaults to 4096.

buffer is the buffer size in the tile coordinate system. Defaults to 256.

clip_geom controls whether geometries are clipped at tile boundaries. Defaults to true.

Usage notes

For small tiles, setting res_prec to a large value may filter out a significant number of vectors and leave the tile visually sparse. Choose a value appropriate for your zoom level.
This function is not suitable for point data visualization. Use it for line and polygon (vector) data of varying sizes.

Example

The following query filters to only vectors that occupy at least two pixels along either axis of the tile at zoom level 0. This approach is suitable for line and polygon data — not point data.

-- Only vectors with a minimum of two pixels in the x-axis or y-axis are included.
WITH mvtgeom AS (
    SELECT ST_AsMVTGeomEx(
               geom,
               ST_Transform(ST_TileEnvelope(0, 0, 0), 4326),
               2
           ) AS geom
    FROM geom_table
    WHERE geom && ST_Transform(ST_TileEnvelope(0, 0, 0), 4326)
)
SELECT ST_AsMVT(mvtgeom.*);