All Products
Search
Document Center

PolarDB:ST_Generalize

Last Updated:Mar 28, 2026

Aggregates a geographic grid or an array of geographic grids to a coarser (lower-precision) level.

Syntax

geomgrid ST_Generalize(geomgrid gridcode, integer precision);
geomgrid[] ST_Generalize(geomgrid[] gridarray, integer precision, bool degenerated default false);

Parameters

ParameterDescription
gridcodeThe geographic grid object to aggregate.
gridarrayThe array of geographic grid objects to aggregate.
precisionThe aggregation level.
degeneratedSpecifies whether to use a degenerated grid. Default: false.

Description

ST_Generalize moves a grid up the hierarchy — from a finer level to a coarser level. The precision parameter sets the target level; the result is the ancestor grid that contains the input at that level.

For the array variant, each grid in gridarray is independently aggregated to the specified precision. The degenerated parameter controls whether degenerated output cells at the target level are included (true) or dropped (false).

Examples

Aggregate a single grid

SELECT ST_AsText(ST_Generalize(ST_GridFromText('GZ0026206440'), 5));
 st_astext
-----------
 GZ00262

Aggregate an array of grids

SELECT ST_Generalize(ST_As3DGrid(
'srid=4490;LINESTRING Z (116 39 2000,116.012 39.009 3000)'::geometry, 10), 8);
                st_generalize
---------------------------------------------
 {01024008722600000000,01024008742600000000}