geos icon indicating copy to clipboard operation
geos copied to clipboard

Error calling unaryUnion with very niche inputs

Open MattTheCuber opened this issue 2 weeks ago • 8 comments

Problem

Running the minimal example below throws a TopologyException. I have been working with @mikedh on an issue in https://github.com/mikedh/trimesh/issues/2488, then @theroggy in https://github.com/shapely/shapely/issues/2358, and it has led us here. Although, we were able to resolve the problem with a workaround, I thought it would be beneficial to share the bug report here.

Minimal Example

Rename extension to .wkt polygons.txt

$ geosop -a polygons.wkt unaryUnion
Run-time exception: TopologyException: Ring edge missing at -1.5732562941774 7.904434391775184

Note: Running this command on a test file (like this) works fine, it only fails with this specific input.

Environment

  • Red Hat Enterprise Linux 9.6 (I believe it also occurs on Windows 11)
  • GEOS v3.14.1

MattTheCuber avatar Dec 09 '25 13:12 MattTheCuber

Nice input. 😄 @dr-jts this also fails in JTS.

org.locationtech.jts.geom.TopologyException: 
found non-noded intersection between 
LINESTRING ( -2.4439364332645837 1.2105204387996402, -2.339023287928491 0.5217725913707031 ) 
and 
LINESTRING ( -2.339023287928491 0.521772591370703, -2.339023287928491 0.5217725913707032 ) 
[ (-2.339023287928491, 0.5217725913707031, NaN) ]

pramsey avatar Dec 09 '25 17:12 pramsey

this also fails in JTS.

How are you running this? It works for me in TestBuilder using OverlayNGRobust (which is the standard code path):

Image

dr-jts avatar Dec 09 '25 20:12 dr-jts

Ah, I was using "OverlayNG" not "OverlayNGRobust".

pramsey avatar Dec 09 '25 20:12 pramsey

And come to think of it, I cannot replicate either...

./bin/geosop -v -a $HOME/Downloads/polygons.wkt unaryUnion
Input A: WKT file /Users/pramsey/Downloads/polygons.wkt
Read 1 geometries, 208 vertices  -- 623 usec
[ 1] unaryUnion: A[1] GeometryCollection( 208 )  -> Polygon( 36 )  --  2,393 usec
POLYGON ((-10.944553152533185 -68.40940481609661, -11.477396284004609 -55.48211427005445, -9.665730626080167 -46.63520657856243, -6.1606394792661385 -39.56368325939373, -5.697131690799814 -35.168144298848155, -5.923720686905879 -16.235821209122424, -4.04425967854734 -1.346139278400533, -3.446366736465011 0.8921630819262439, -4.104516608506552 12.112119256727777, -2.1982913417356875 26.994559772208923, 1.3464458329117068 33.01070476711907, 4.532507979820731 35.61904346954334, 6.612777301917237 36.063185154347444, 8.051902692875965 16.1745493529877, 9.854949279150409 -14.031791236751758, 8.143645356366674 -24.8074378190185, 4.566295472788307 -31.108901689146226, 3.8662823257961505 -32.00373266176222, 4.045017485226917 -44.591813884340915, 2.1655564768683804 -59.48149581506282, -0.4797554601452791 -67.79429254345098, -4.725701460041062 -67.88249984010983, -8.779906989660152 -68.10055885244654, -10.944553152533185 -68.40940481609661), (-0.6817281672365398 -10.358260061109213, -1.8245502143214751 -2.855709047101134, -1.824550214321475 -2.8557090471011377, -0.6817281672365398 -10.358260061109213), (3.0243411341241897 -3.518368608349892, 3.440000034417878 -2.8753204824372216, 3.440000034417878 -2.875320482437221, 3.0243411341241897 -3.518368608349892), (5.108100725945679 -0.294673170993445, 5.108100725945679 -0.2946731709934451, 6.776547203732532 2.2865090915982376, 5.108100725945679 -0.294673170993445))
Ran 1 unaryUnion ops ( 208 vertices)  -- 2,393 usec    (GEOS 3.14.2dev)

pramsey avatar Dec 09 '25 20:12 pramsey

For information, we weren't able to reproduce on windows but apparently the error did occur on Linux, on both platforms with GEOS 3.14.1 installed via conda-forge. https://github.com/shapely/shapely/issues/2358#issuecomment-3618431130

Not sure what platform you are trying to reproduce on?

theroggy avatar Dec 09 '25 20:12 theroggy

MacOS ARM64.

pramsey avatar Dec 10 '25 18:12 pramsey

I added a temporary unit test in the shapely test suite... and it indeed only seems to fail on linux specifically:

github runner image architecture os result
ubuntu-latest intel X64 linux unary_union test fails
ubuntu-24.04-arm arm linux unary_union test fails
windows-latest intel X64 windows OK
windows-11-arm arm windows build fails
macos-15-intel intel X64 macos OK
macos-latest arm macos OK

References:

theroggy avatar Dec 11 '25 21:12 theroggy

Confirmed failure of OverlayNGRobust::Union on Linux, https://github.com/Snowflake-Labs/geos/commit/525d5389416641aff0cf6f5fce1e30d17ea7fdd5

pramsey avatar Dec 12 '25 18:12 pramsey