All Products
Search
Document Center

PolarDB:ST_BuildPyramid

Last Updated:Mar 28, 2026

Builds a vector pyramid for a spatial geometry data table, pre-tiling geometry data across zoom levels to accelerate map rendering at varying scales.

Syntax

boolean ST_BuildPyramid(cstring table, cstring geom, cstring fid, cstring config)

Parameters

ParameterDescription
tableThe name of the spatial geometry data table.
geomThe name of the geometry column.
fidThe name of the element ID field.
configPyramid build options, specified as a JSON string. See Config fields for the full list of supported fields.

Config fields

The config parameter accepts a JSON object with the following fields.

FieldTypeDefaultDescription
namestringSame as the table nameThe name of the pyramid.
parallelint0The maximum number of tasks to run in parallel. Set to 0 for no limit. Requires the max_prepared_transactions parameter to be configured.
tileSizeint1024The tile size. Must be greater than 0 and less than 4096.
tileExtendint8The tile extension size of the pyramid. Must be greater than 0.
userExtentarray[double]nullThe bounding box that constrains pyramid generation, specified as [minx, miny, maxx, maxy]. Set to [] to use no bounding box.
splitSizeint10000The maximum number of elements per index node. A larger value produces a sparser pyramid.
maxLevelint16The maximum number of zoom levels. Valid values: 020.
sourceSRSint-1The Spatial Reference Identifier (SRID) of the source data. Set to -1 to read the SRID from the table metadata.
destSRSint3857The EPSG code for the output tile coordinate system. Supported values: 3857 (EPSG:3857, Web Mercator) and 4326 (EPSG:4326, WGS84).
buildRulesarray[object]nullPer-zoom-level rules for pyramid generation. See buildRules fields.

buildRules fields

Each object in the buildRules array applies a rule to a set of zoom levels. Rules let you control data density per level — for example, filter out minor features at low zoom levels to reduce data volume, and include full attribute detail at high zoom levels to support map interactivity.

FieldTypeDescription
levelarray[int]The zoom levels to which the rule applies.
valueobjectThe rule definition. Contains the fields below.
value.filterstringA PostgreSQL filter expression to include only matching features.
value.attrFieldsarray[string]The attribute fields to include in the Mapbox Vector Tile (MVT) output.
value.mergearray[string]Filter conditions used to group data records.

Config example

{
   "name": "hello",
   "parallel": 4,
   "tileSize": 512,
   "tileExtend": 8,
   "userExtent": [-180, -90, 180, 90],
   "splitSize": 5000,
   "maxLevel": 16,
   "destSRS": 3857,
   "buildRules": [
     {
       "level": [0, 1, 2],
       "value": {
         "filter": "code!=0",
         "attrFields": ["name", "color"],
         "merge": ["code=1"]
       }
     }
   ]
}

Examples

Build a pyramid with default settings

Pass an empty string as config to use all default values.

SELECT ST_BuildPyramid('roads', 'geom', 'id', '');

Expected output:

 st_buildpyramid
-----------------
 t