yeesian / ArchGDAL.jl

A high level API for GDAL - Geospatial Data Abstraction Library
https://yeesian.github.io/ArchGDAL.jl/stable/
Other
137 stars 25 forks source link

flattento2d! and setcoorddim! need to update the geometry type paramter #333

Open rafaqz opened 1 year ago

rafaqz commented 1 year ago

Since we have a type parameter now, changing the type in GDAL is not enough, we need to update the type and return a new object.

mattwigway commented 3 weeks ago

I just ran into this issue, and was looking at how to fix it. It seems like what needs to happen is that a new Geometry/IGeometry should be constructed and returned based on the pointer. The place I'm running into difficulty is that when the old geometry object is GC'ed on the Julia side, it still has a pointer to the GDAL geometry and will free it, leaving the new geometry pointing at unallocated memory. I can think of three solutions:

  1. Somehow remove the finalizer from the old object. In my tests, calling finalizer(new_function, object) replaces the finalizer rather than adding a second finalizer, but this behavior doesn't seem to be documented, and I am hesitant to rely on it.
  2. Add a boolean field to the Geometry objects that indicates that the object no longer "owns" its pointer, and check that in destroy
  3. Set ptr to a null pointer (or change ptr to a Union{Ptr, Nothing} and set to nothing), and check that in destroy.

I kinda like changing ptr to a Union{Ptr, Nothing} as it avoids accidental dereferencing of null pointers—not sure how it will affect performance though, or backwards compatibility with any serialized ArchGDAL geometries that may exist.