All Products
Search
Document Center

PolarDB:ST_AsMVTGeomEx

Last Updated:Mar 28, 2026

Extends ST_AsMVTGeom with a res_prec parameter that filters out geometry objects too small to affect the display, reducing the volume of vector data transferred and improving tile rendering 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 The geometry object to convert.

bounds The rectangular boundaries of the tile, excluding the buffer.

res_prec The minimum pixel threshold for rendering. Geometry objects whose maximum pixel span in the x-axis or y-axis falls below this value are filtered out. Default value: 1.

extent The tile size in the tile coordinate system. Default value: 4096.

buffer The buffer size in the tile coordinate system. Default value: 256.

clip_geom Specifies whether to clip geometry objects at tile boundaries. Default value: true.

Usage notes

  • This function is designed for vector data of varying sizes. It is not suitable for point data.
  • For small tiles, setting res_prec to a large value may cause many vectors to become invisible.

Example

Filter out geometry objects that span fewer than two pixels in the x-axis or y-axis of the current tile before generating the MVT output:

-- Only vectors spanning at least 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.*);