ArchGDAL.jl icon indicating copy to clipboard operation
ArchGDAL.jl copied to clipboard

GDAL geometries can not be saved to JLD2 files

Open alex-s-gardner opened this issue 1 year ago • 3 comments

When trying to save GDAL geometries to .jld2 files they are saved as NULL Geometry. @asinghvi17 thinks this has to do with the c-pointers to memory that is not handled correctly by JLD2.

Being able to save GDAL geometries to .jld2 files would be super useful for users like me who work with DimensionalData arrays and GDAL geometries in the same table.

alex-s-gardner avatar Nov 13 '24 20:11 alex-s-gardner

Yeah, while I understand the need, this can't work.

A pointer is just that, it points to a bit of temporary memory (on your machine). Keeping track of that memory is hard enough while in Julia (as you saw in the other issue), and straight up impossible for JLD2, because if you close Julia, you close the GDAL library and poof, that memory/geometry is gone (which is why JLD2 plays it safe and doesn't save the pointers). And you can't be smart about this, copying the memory, because it's a foreign (GDAL) structure. The pointer only points to a beginning, and only GDAL understands it from there on.

What would work is creating native geometries in Julia (like WKB, as ArchGDAL can read/write those), and saving those to JLD2.

evetion avatar Nov 13 '24 21:11 evetion

JLD2's serialization methods can be overridden. I was not sure how to save geometries efficiently but your WKB tip pointed me in the right direction :D

Now we just need a method to set the CRS of a geometry. Probably needs to be wrapped from GDAL.

asinghvi17 avatar Nov 13 '24 21:11 asinghvi17

Reopening due to https://github.com/yeesian/ArchGDAL.jl/pull/448#issuecomment-2475470839

yeesian avatar Nov 14 '24 05:11 yeesian