4

I'm attempting to determine 1) what "ring edge missing" means in the following PostGIS/GEOS error message, and 2) why ST_Intersection throws it for certain gridSize parameters but not for others.

ERROR:  lwgeom_intersection_prec: GEOS Error: TopologyException: Ring edge missing at -101448.694 2143744.5019999999
SQL state: XX000

This error occurs when I attempt... :

st_intersection(tbl1.shape, tbl2.shape, 0.001)

... but not when I attempt:

st_intersection(tbl1.shape, tbl2.shape, 0.01)

The input polygons are fairly large (i.e. many vertices covering large geographic extents), but are otherwise relatively simple. They are POLYGON and not MULTIPOLYGON.

The phrase "ring edge missing" doesn't provide much detail. Google searches bring up one other instance from a semi-related GIS StackExchange post. I've also searched for "lwgeom_intersection_prec", but the resulting links (e.g. here and here) result in dead ends when searching further for the specific "ring edge missing" error. I don't know where else I can go to find more information about the specific error and what it means.

Trying a different approach: when I inspect any coordinates thrown by the error, nothing jumps out at me--it appears to be a very normal polygon edge. All polygons are ST_IsValid. I don't have any clue why changing the gridSize parameter in ST_Intersection results in an error.

My environment:

PostgreSQL 14.9
PostGIS 3.4.0
GEOS 3.12.0

What does the "ring edge missing" error mean? How can I interrogate the error or my data further to figure out why it's occurring?

(And if someone can post a link detailing PostGIS/GEOS error messages or further details about the gridSize parameter, that would be very helpful for troubleshooting in the long run.)

5
  • 1
    see if the original geometries are still valid after applying st_snapToGrid on them.
    – JGH
    Dec 5, 2023 at 21:02
  • ST_SnapToGrid was key in resolving the particular error as there ended up being some "slivver" polygons in certain scenarios for one of my inputs--meaning I didn't check my inputs closely enough. This solves the second part of my question, but doesn't answer what "ring edge missing" means. Does this indicate an invalid polygon/multipolygon? Dec 6, 2023 at 1:47
  • 2
    Agreed that "ring edge missing" is a cryptic error (and could be improved). It indicates one of two situations: an invalid input geometry; or a robustness issue (AKA algorithm bug). For an invalid input, ST_MakeValid can be used to correct the problem. For a robustness problem, you might be able to perturb the inputs .
    – dr_jts
    Dec 6, 2023 at 5:25
  • 2
    The overlay functions should work for any valid input. So even though your geometries contain "slivers", ST_Intersection should still work. But there are still a few limitations to the algorithm that may prevent this.
    – dr_jts
    Dec 6, 2023 at 5:28
  • This conversation has answered my question. If it's okay by @JGH and @dr_jts, I'll put the following into an answer and accept it: The "ring edge missing" error indicates either an invalid geometry input or a bug with the spatial function. In this case it appears to be the latter since my geometries are all ST_IsValid (with the 0 flag for OGC geometry). As to how I can interrogate my data further, ST_SnapToGrid helped highlight some precision problems in my input data (an ST_Union in a view using too small a gridSize parameter) that I did not fully appreciate. Dec 7, 2023 at 0:42

2 Answers 2

6

This error is caused by a robustness issue in the GEOS overlay code used in PostGIS. So essentially in this case it's a bug, not a problem with your geometry inputs.

That is a fairly recent version of GEOS. If you can post the input geometries causing the problem here (or better, in the PostGIS or GEOS issue trackers) we can look at them to see if there is an issue that can be addressed.

1
  • It appears one of my inputs was actually not as simple as I thought--see comment above. Dec 6, 2023 at 1:48
2

An improvement has recently landed in GEOS 3.12.1 that fixed a similar error for me when I used grid_size on a geometry. Might be worth to try upgrading and see if it solves your problem as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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