Confusion about ST_ReducePrecision and geometry validity

Marco Boeringa marco at boeringa.demon.nl
Tue Jun 11 12:37:28 PDT 2024


Hi,

Currently, the help page of PostGIS's ST_ReducePrecision command more or 
less suggests that ST_ReducePrecision can be used as kind of "drop-in" 
replacement of ST_MakeValid. The actual text reads:

/"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)"/

However, a first test replacing:

ST_CollectionExtract(ST_MakeValid(<SOME OTHER GENERALIZATION CODE>),3)

with:

ST_ReducePrecision(<SOME OTHER GENERALIZATION CODE>),<GRID SIZE>)

failed on some geometries with a processing error.

Replacing the first try with:

ST_ReducePrecision(ST_CollectionExtract(ST_MakeValid(<SOME OTHER 
GENERALIZATION CODE>),3),<GRID SIZE>)

did succeed.

This suggest to me that the help page should actually read something like:

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

Unlike ST_SnapToGrid the returned geometry is guaranteed to be valid, 
with no ring self-intersections or collapsed components, if the input 
geometry itself is valid. If the input geometry is invalid, there is no 
guarantee the output will be valid. Use ST_MakeValid to ensure the input 
is valid before running this command if the input data may contain 
invalid geometries."/

Is my interpretation of how//ST_ReducePrecision handles validity as 
reflected by this suggested updated help text correct?/
/

Marco/
/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20240611/b16050d2/attachment.htm>


More information about the postgis-users mailing list