PostGISGeometry Editors

ST_QuantizeCoordinates

What is ST_QuantizeCoordinates?

ST_QuantizeCoordinates zeroes trailing bits of the floating-point mantissa of each coordinate so that resulting geometry is more compressible by PostgreSQL's TOAST. Control the preserved precision per axis independently.

SQL
ST_QuantizeCoordinates(geometry g, int prec_x, int prec_y = prec_x, int prec_z = prec_x, int prec_m = prec_x)geometry

prec_* is the number of decimal digits to preserve. Available from PostGIS 2.5.

When would you use ST_QuantizeCoordinates?

Use ST_QuantizeCoordinates before storing large geometry columns to reduce on-disk size and TOAST overhead, especially for centimetre-precise GPS tracks where the last bits are survey noise rather than signal. Three decimals (millimetre precision at the equator on EPSG:4326 is excessive, so quantize) is usually enough for cartographic output.

In tile-generation pipelines, quantising before ST_AsMVT and ST_AsGeobuf reduces tile size and network transfer without visibly affecting rendered output.

FAQs

Does it make geometry invalid?

It tries not to. Quantisation is applied in a way that rounds toward the nearest representable value and avoids flipping ring orientation or creating duplicate vertices inside a segment.

How much precision should I keep?

Depends on CRS. For EPSG:4326, 6 decimal digits is roughly 11 cm at the equator — usually enough. For metric CRSs, 3 decimals is millimetre. Over-quantising can collapse vertices and change topology.

What version introduced ST_QuantizeCoordinates?

PostGIS 2.5.

Is this different from ST_SnapToGrid?

Yes. ST_SnapToGrid snaps coordinates to a discrete grid with a configurable origin and cell size, producing visible geometry change. ST_QuantizeCoordinates manipulates binary representation for compression with minimal visible change.