geopandas / pyogrio

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

Refactor cleanup of GDAL objects / close of dataset on write #396

Closed brendan-ward closed 2 months ago

brendan-ward commented 2 months ago

Resolves #394

This reorganizes the write functions a bit to make sure that we're always cleaning up allocated objects (feature, geometry, etc) in the finally block in case of exception, which reduces the amount of inner try / catch blocks we need to have. This should then correctly release those within the loops under the non-exception path.

This also strips out the OGRReleaseDataSource we were using in various places for GDALClose, which is the current recommended function.

rouault commented 2 months ago

I'm perhaps hijacking this PR a bit but just to mention that starting with GDAL 3.7, GDALClose() returns a CPLErr return code (previously was void). This can be a way of checking that everything has been successfullly written (some formats completely defer writing at close time). Cf https://gdal.org/development/rfc/rfc91_dataset_close.html