All Products
Search
Document Center

PolarDB:ST_Generalize

Last Updated:Mar 28, 2026

Rolls up a geographic grid or an array of geographic grids to a coarser aggregation 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 grids to aggregate.
precisionThe target aggregation level.
degeneratedSpecifies whether to use a degenerated grid. Defaults to false.

Description

ST_Generalize aggregates a geographic grid or an array of geographic grids to a lower aggregation level (coarser resolution).

For the array overload, all grids in the input array are aggregated to the specified precision.

Examples

Aggregate a single grid to a lower precision

The following example aggregates grid GZ0026206440 (precision 10) to precision 5. The output grid GZ00262 covers the area of the original grid at a coarser resolution.

SELECT ST_AsText(ST_Generalize(ST_GridFromText('GZ0026206440'), 5));

Result:

 st_astext
-----------
 GZ00262

Aggregate an array of grids derived from a 3D geometry

The following example generates a geomgrid[] from a 3D line string at precision 10, then aggregates all grids to precision 8.

SELECT ST_Generalize(ST_As3DGrid(
'srid=4490;LINESTRING Z (116 39 2000,116.012 39.009 3000)'::geometry, 10), 8);

Result:

                st_generalize
---------------------------------------------
 {01024008722600000000,01024008742600000000}

See also

  • ST_GridFromText: Create a geomgrid object from its text representation.

  • ST_As3DGrid: Generate a geomgrid[] from a 3D geometry at a specified precision.

  • ST_AsText: Convert a geomgrid object to its text representation.