2

I am getting this PostGIS error:

ERROR: lwgeom_unaryunion_prec: GEOS Error: TopologyException: Ring > edge missing at 577690.01999999955 213605.69999999925 SQL state: XX000

I have checked that the table has the correct SRID set, and I have checked that all polygons are considered valid by running this (and getting a result of 0):

SELECT COUNT(*)
FROM table1 AS a
WHERE NOT ST_IsValid(a.geom)
;

Just in case it helped anyway, I also created a copy of the table using ST_MakeValid on all polygons. Unsurprisingly, given the ST_IsValid results, this didn't remove the error.

I realise that I can inspect the site of the error using the coordinates given. At maximum magnification in QGIS I can't see a problem with the polygon in question.

Is this likely to be a numerical precision issue as discussed in ST_Union Topology exception despite of valid geometries ?

4
  • 1
    It is likely a numerical precision issue. Using ST_Snap in the SQL may help, but the error may happen in coordinates which are created by the algorithm. JTS library has received some improvements with robustness. Perhaps they are ported into GEOS and lwgoem in the latest versions.
    – user30184
    Jun 3 at 9:01
  • @user30184 Thank you for this advice. By way of update, I am trying a re-run using the grid-snapping argument in ST_Union (set to 0.00000001), and it has not yet thrown up the same error (which previously happened within seconds). I expect this operation to take hours to run, so will update on whether it completes successfully in due course. Thanks again.
    – MDB
    Jun 3 at 10:25
  • @user30184 This worked - thank you for pointing me towards snapping as the answer. Do you want to write the answer or shall I?
    – MDB
    Jun 3 at 17:16
  • 1
    Please write it yourself, you did the hard work and testing.
    – user30184
    Jun 3 at 17:22
2

With thanks to @user30184 for the pointer...

This was a numerical precision issue, and was solved by adding the snap-to-grid argument to ST_Union. I.e.:

ST_Union(a.geom,0.00000001)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.