Name

ST_ReducePrecision — Returns a valid geometry with points rounded to a grid tolerance.

Synopsis

geometry ST_ReducePrecision(geometry g, float8 gridsize);

Description

Returns a valid geometry with all points rounded to the provided grid tolerance, and features below the tolerance removed.

Unlike ST_SnapToGrid the returned geometry will be valid, with no ring self-intersections or collapsed components.

Precision reduction can be used to:

  • match coordinate precision to the data accuracy

  • reduce the number of coordinates needed to represent a geometry

  • ensure valid geometry output to formats which use lower precision (e.g. text formats such as WKT, GeoJSON or KML when the number of output decimal places is limited).

  • export valid geometry to systems which use lower or limited precision (e.g. SDE, Oracle tolerance value)

Availability: 3.1.0.

Requires GEOS >= 3.9.0.

Examples

Code
SELECT ST_ReducePrecision('POINT(1.412 19.323)', 0.1);
Output
POINT(1.4 19.3)
Figure
Geometry figure for visual-st-reduceprecision-01
Code
SELECT ST_ReducePrecision('POINT(1.412 19.323)', 1.0);
Output
POINT(1 19)
Figure
Geometry figure for visual-st-reduceprecision-02
Code
SELECT ST_ReducePrecision('POINT(1.412 19.323)', 10);
Output
POINT(0 20)
Figure
Geometry figure for visual-st-reduceprecision-03

Precision reduction can reduce number of vertices

Code
SELECT ST_ReducePrecision('LINESTRING (10 10,19.6 30.1,20 30,20.3 30,40 40)', 1);
Output
LINESTRING (10 10, 20 30, 40 40)
Figure
Geometry figure for visual-st-reduceprecision-04

Precision reduction splits polygons if needed to ensure validity

Code
WITH data(geom) AS (
  VALUES ('POLYGON ((10 10,60 60.1,70 30,40 40,50 10,10 10))'::geometry)
)
SELECT geom AS input,
       ST_ReducePrecision(geom, 10) AS reduced
FROM data;
Output
-[ RECORD 1 ]------------------------------------------------
input   | POLYGON((10 10,60 60.1,70 30,40 40,50 10,10 10))
reduced | MULTIPOLYGON(((10 10,40 40,50 10,10 10)),((40 40,60 60,70 30,40 40)))
Figure
Geometry figure for visual-st-reduceprecision-05