Extends ST_AsMVTGeom with a res_prec parameter that filters out geometries too small to affect the display, reducing frontend and backend processing load, network overheads, 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
| Parameter | Type | Default | Description |
|---|---|---|---|
geom | GEOMETRY | — | The geometry to convert. |
bounds | BOX2D | — | The rectangular boundaries of the tile, excluding the buffer. |
res_prec | INTEGER | 1 | The filtering threshold. A geometry is filtered out if its maximum pixel span in the x-axis or y-axis is less than this value. |
extent | INTEGER | 4096 | The tile size in the tile coordinate system. |
buffer | INTEGER | 256 | The buffer size in the tile coordinate system. |
clip_geom | BOOLEAN | true | Specifies whether to clip geometries at tile boundaries. |
Usage notes
Not suitable for point data visualization. Use this function for vector data of varying sizes.
For small tiles, setting
res_precto a large value may cause many vectors to become invisible.
Examples
The following query visualizes only vectors with a minimum span of two pixels in the x-axis or y-axis of the current tile.
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.*);