geopandas / pyogrio

Vectorized vector I/O using OGR
https://pyogrio.readthedocs.io
MIT License
276 stars 24 forks source link

GEOS 3.13 is causing curve geometry tests to segfault #478

Open brendan-ward opened 2 months ago

brendan-ward commented 2 months ago

First observed in the conda tests, which are pulling in GEOS 3.13 which added support for curve geometry types. I can reproduce the segfault locally when installing deps from conda-forge and building latest pyogrio.

It looks like the latest GDAL Docker versions we're testing against still use GEOS 3.12, so we aren't yet seeing this issue in the other CI tests - but it may be lurking around the corner. Until there is a version of GDAL built against GEOS 3.13 it is harder to test against this configuration outside of the conda packages.

brendan-ward commented 2 months ago

Looks like homebrew GDAL 3.9.2 includes GEOS, so I should be able to compile against that locally and see if this segfaults when using GDAL outside of conda-forge.

brendan-ward commented 2 months ago

Narrowed it down a bit: this happens where use_arrow=True when reading certain curve geometries available in our test suite:

(we don't have Surface at the moment)

Curve doesn't segfault but raises another error.

I can also reproduce the issue locally when compiling against homebrew GDAL and compiling shapely against GEOS 3.13, which makes this easier to investigate.

When we are reading geometries using without using Arrow, we can detect if a geometry is nonlinear and have GDAL force it to a linear type before we read it. However, when using Arrow, we read the raw WKB with GDAL, and count on shapely to be able to parse it. The segfault is occurring in shapely.from_wkb with these nonlinear types.

However, GEOS 3.13 appears to work fine:

❯ geosop -a "010C00000001000000010A00000001000000010200000004000000D2936CD801D357C01F7CE5EED1AE4F402EDD365958A657C065B26029F3884A4056D
1DE08466D52C0ED7574EB21134E40D2936CD801D357C01F7CE5EED1AE4F40"
MULTISURFACE (CURVEPOLYGON ((-95.29698763468994 63.36578165250125, -94.5991423640996 53.06992070409323, -73.7073995758013 60.149472648492385, -95.29698763468994 63.36578165250125)))
theroggy commented 2 months ago

Shapely with GEOS 3.13 also seems to crash on the wkt:

I've had a quick look at the shapely code, but don't immediately see where it can go wrong specifically on the curve types...

So I opened an issue in shapely: https://github.com/shapely/shapely/issues/2159

import shapely

wkt = "MULTISURFACE (CURVEPOLYGON ((-95.29698763468994 63.36578165250125, -94.5991423640996 53.06992070409323, -73.7073995758013 60.149472648492385, -95.29698763468994 63.36578165250125)))"
print(shapely.from_wkt(wkt))
print("here")