Opened 4 years ago

Closed 4 years ago

#4725 closed defect (fixed)

ST_MakeValid causes drastic loss of precision

Reported by: atlight Owned by: pramsey
Priority: medium Milestone: PostGIS GEOS
Component: postgis Version: 3.0.x
Keywords: Cc:

Description

ST_MakeValid experiences a drastic loss of precision on a particular polygon input. It is a complex polygon with five somewhat pathological interior rings.

The bug only occurs when all five of the interior rings (holes) are present. When one is removed, no precision loss occurs.

What is especially problematic is, when this polygon is part of a MultiPolygon and ST_MakeValid is applied to the MultiPolygon, the entire MultiPolygon loses precision in this manner, rendering the geometry useless.

I've uploaded the WKB of the offending polygon as an attachment. When inserted into a table a with geometry column geom, I get the following output:

scratch=# SELECT SUBSTRING(ST_AsText(geom) FROM 1 FOR 100) FROM a;
                                              substring
------------------------------------------------------------------------------------------------------
 POLYGON Z ((144.96322622986 -37.741979743636 0,144.96322622986 -37.741979743636 0,144.963225440888 -
(1 row)

scratch=# SELECT SUBSTRING(ST_AsText(ST_MakeValid(geom)) FROM 1 FOR 100) FROM a;
                                              substring
------------------------------------------------------------------------------------------------------
 GEOMETRYCOLLECTION Z (MULTIPOLYGON Z (((144.963224 -37.74198 0,144.963222 -37.74198 0,144.963221 -37
(1 row)

Attachments (1)

pathpolybin (32.3 KB ) - added by atlight 4 years ago.
Hex WKB of offending polygon

Download all attachments as: .zip

Change History (4)

by atlight, 4 years ago

Attachment: pathpolybin added

Hex WKB of offending polygon

comment:1 by atlight, 4 years ago

Milestone: PostGIS 3.0.2PostGIS 3.1.0
Version: 2.5.x3.0.x

comment:2 by pramsey, 4 years ago

Milestone: PostGIS 3.1.0PostGIS GEOS

As expected, this is a result of GEOS precision reduction routines in the old overlay engine trying to back off from repeated topology failures during overlay. And as hoped, the new overlay engine does not display the same behaviour. A valid output is generated, and the precision is basically the same.

postgis31=# select st_xmin(ST_MakeValid(geom)) FROM a;
      st_xmin      
-------------------
 144.9632208323141
(1 row)

postgis31=# select st_xmin(geom) FROM a;
      st_xmin      
-------------------
 144.9632208323141
(1 row)

The solution will be to upgrade to GEOS 3.9 when it is released.

comment:3 by pramsey, 4 years ago

Resolution: fixed
Status: newclosed

GEOS 3.9 is released.

Note: See TracTickets for help on using tickets.