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
| Parameter | Description |
|---|---|
gridcode | The geographic grid object to aggregate. |
gridarray | The array of geographic grid objects to aggregate. |
precision | The aggregation level. |
degenerated | Specifies 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
-----------
GZ00262Aggregate 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}