Creates a vector pyramid for a spatial geometry data table to accelerate spatial data rendering.
Syntax
boolean ST_BuildPyramid(cstring table, cstring geom, cstring fid, cstring config)Parameters
| Parameter | Description |
|---|---|
table | The name of the spatial geometry data table. |
geom | The name of the geometry column. |
fid | The name of the element ID field. |
config | The pyramid configuration, specified as a JSON string. |
config fields
| Field | Type | Default | Description |
|---|---|---|---|
name | string | Same as the table name | The name of the pyramid. |
parallel | integer | 0 | The maximum number of tasks that run in parallel to build the pyramid. Requires the max_prepared_transactions parameter to be set. Set to 0 to remove the limit. |
tileSize | integer | 1024 | The tile size of the pyramid. Valid values: greater than 0 and less than 4096. |
tileExtend | integer | 8 | The tile extension size of the pyramid. Valid values: greater than 0. |
userExtent | array[double] | null | The geographic extent of the pyramid, defined as a JSON array with four values: minx, miny, maxx, and maxy. Set to [] to use a null value. |
splitSize | integer | 10000 | The maximum number of elements per index node split. A higher value produces a sparser pyramid. |
maxLevel | integer | 16 | The maximum number of pyramid levels. Valid values: 0 to 20. |
sourceSRS | integer | -1 | The spatial reference system (SRS) of the source data. By default, the function reads the spatial reference identifiers (SRIDs) from the table metadata. |
destSRS | integer | 3857 | The EPSG code of the tile coordinate system. Valid values: 3857 (EPSG 3857) and 4326 (EPSG 4326). |
buildRules | array[object] | null | The rules for building the pyramid. Multiple rules are supported. |
buildRules fields
| Field | Type | Description |
|---|---|---|
level | array[integer] | The pyramid levels to which the rule applies. |
value | object | The rule configuration. Contains the following sub-fields: filter, attrFields, and merge. |
value.filter | string | A PostgreSQL filter expression to apply to the data. |
value.attrFields | array[string] | The attribute fields to include when using the Mapbox Vector Tile (MVT) format. |
value.merge | array[string] | The filter conditions for grouping 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 for a spatial geometry data table named roads:
SELECT ST_BuildPyramid('roads', 'geom', 'id', '');Expected output:
st_buildpyramid
---------------
t