ST_SNAP_TO_GRID()
All functions > GEOSPATIAL > ST_SNAP_TO_GRID()
Snaps all vertices of a geometry to a uniform grid with the given cell size.
Signatures
Snap to grid
Returns: Geometry with snapped vertices; sub kind is preserved but may collapse to empty
ST_SNAP_TO_GRID(geo: T, size: DOUBLE) → GEOM_MULTIANY sql
| Parameter | Type | Required | Description |
|---|---|---|---|
geo | T | Yes | Geometry value |
size | DOUBLE | Yes | Grid cell size in SRID coordinate units |
With:
T: Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY
Signature notes:
- Rounds each vertex coordinate to the nearest multiple of size
- Snapping follows spatial grid rules; behavior at exact half-step boundaries can differ from naive scalar rounding of coordinates alone
- May collapse small geometries to empty if the grid is coarser than the shape
- May produce invalid geometries (self-intersections) after snapping; validate with ST_ISVALID
- GEOMETRY only; for geographic use, reproject first: ST_TRANSFORM to a metric CRS, snap, then ST_TOGEOGRAPHY
- Not supported on Trino or DataFusion
- Returns NULL if any input is NULL
Examples
FeatureQL
SELECT
f1 := ST_ASTEXT(ST_SNAP_TO_GRID(ST_GEOMPOINT(1.23456, 7.89012), 0.01)) -- Snap a point to a 0.01 unit grid
;Result
| f1 VARCHAR |
|---|
| POINT (1.23 7.89) |
On this page