JuliaGeo / GeometryOps.jl

GeoInterface-based geometry operations
https://juliageo.org/GeometryOps.jl/
MIT License
19 stars 4 forks source link

`enumerate(GI.getpoint(geom))` is not type inferred on polygons #194

Open asinghvi17 opened 1 month ago

asinghvi17 commented 1 month ago

julia> eltype(enumerate(GI.getpoint(p56)))
Tuple{Int64, Any}

julia> const p5 = p56
GeoInterface.Wrappers.Polygon{false, false, Vector{GeoInterface.Wrappers.LinearRing{false, false, Vector{Tuple{Float64, Float64}}, Nothing, Nothing}}, Nothing, Nothing}(GeoInterface.Wrappers.LinearRing{false, false, Vector{Tuple{Float64, Float64}}, Nothing, Nothing}[GeoInterface.Wrappers.LinearRing{false, false, Vector{Tuple{Float64, Float64}}, Nothing, Nothing}([(0.0, 0.0), (0.0, 10.0), (10.0, 10.0), (10.0, 0.0)], nothing, nothing)], nothing, nothing)

julia> eltype(enumerate(GI.getpoint(p5)))
Tuple{Int64, Any}

julia> typeof(enumerate(GI.getpoint(p5)))
Base.Iterators.Enumerate{Base.Iterators.Flatten{Base.Generator{Vector{GeoInterface.Wrappers.LinearRing{false, false, Vector{Tuple{Float64, Float64}}, Nothing, Nothing}}, GeoInterface.var"#6#7"}}}

Not sure how bad this is for performance - maybe we need a point enumerator wrapper type thing which is known to be type stable (and maybe also known to emit tuple/svector type points)?

rafaqz commented 1 month ago

What about without enumerate

asinghvi17 commented 1 month ago

~That's a vector so type stability is fine I think~

Ah, there's the problem. I guess getpoint for polygons returns a Iterators.Flatten which has eltype of Any.

getpoint(GI.getexterior(p56)) is a vector so no worries about eltype there.

rafaqz commented 1 month ago

Yeah it's double nested for Polygons. We could make a better iterator in GeoInterface.