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

Stop using `GI.coordinates` in convert functions

Open asinghvi17 opened this issue 8 months ago • 0 comments

This can actually cause some conversions to fail because the create$(geom) function may not have a dispatch for what GI.coordinates outputs, if it's e.g. a StaticArray.

It seems entirely doable to do this manually or in a loop for each type of geometry.

Here's an example for PolygonTrait:

function GeoInterface.convert(
    ::Type{T},
    type::GeoInterface.PolygonTrait,
    geom,
	) where {T<:IGeometry}
    f = get(lookup_method, typeof(type), nothing)
    isnothing(f) && error(
        "Cannot convert an object of $(typeof(geom)) with the $(typeof(type)) trait (yet). Please report an issue.",
    )
    poly = createpolygon()
    foreach(GeoInterface.getring(geom)) do ring
        xs = GeoInterface.x.(GeoInterface.getpoint(ring))   
        ys = GeoInterface.y.(GeoInterface.getpoint(ring))
        subgeom = unsafe_createlinearring(xs, ys)
        result = GDAL.ogr_g_addgeometrydirectly(poly, subgeom)
        @ogrerr result "Failed to add linearring."
    end
    return poly
end

asinghvi17 avatar Apr 26 '25 18:04 asinghvi17