Closed alex-s-gardner closed 1 month ago
Good idea, should be easy to do.
Just need one line that accepts the child type and wraps it in a vector and calls the constructor again. (It's all in an eval loop for every type at once)
Haven't used eval before ... so something like this?
@eval function $geomtype{Z,M}(geom::$childtype; extent::E=nothing, crs::C=nothing) where {Z,M,E,C}
$geomtype([geom]; extent, crs)
end
Fundamentally yes, but we don't have generic dispatch for child types. (Maybe we should?)
is where you'd have to inject a check.
Instead of erroring if geomtrait(geom) isa $trait
, you can check:
if geomtrait($geom) isa $trait
Z1 = isnothing(Z) ? is3d(geom) : Z
M1 = isnothing(M) ? ismeasured(geom) : M
return $geomtype{Z1,M1,T,E,C}(geom, extent, crs)
elseif geomtrait($geom) isa $childtrait
$geomtype{Z, M}([geom], extent, crs) # recurse so this hits the abstractarray dispatch
else
_argument_error(T, $trait)
end
(at least that's the logic I'd envision, can't guarantee this code is correct or free of syntax errors :D )
This is already how geometries are defined, you just need to find where to add that extra check.
Like here:
https://github.com/JuliaGeo/GeoInterface.jl/blob/main/src%2Fwrappers.jl#L187
Closed in #159