Skip to content

Stop using GI.coordinates in convert functions #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
asinghvi17 opened this issue Apr 26, 2025 · 0 comments
Open

Stop using GI.coordinates in convert functions #466

asinghvi17 opened this issue Apr 26, 2025 · 0 comments

Comments

@asinghvi17
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant