Skip to content

Stop using GI.coordinates in convert functions #466

Open
@asinghvi17

Description

@asinghvi17

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions