|
| 1 | +# Implementation of GeoInterface for Base Types |
| 2 | + |
| 3 | +GeoInterface.isgeometry(::Type{<:AbstractVector{<:Real}}) = true |
| 4 | +GeoInterface.geomtrait(::AbstractVector{<:Real}) = PointTrait() |
| 5 | +GeoInterface.ncoord(::PointTrait, geom::AbstractVector{<:Real}) = Base.length(geom) |
| 6 | +GeoInterface.getcoord(::PointTrait, geom::AbstractVector{<:Real}, i) = getindex(geom, i) |
| 7 | + |
| 8 | +GeoInterface.isgeometry(::Type{<:NTuple{N,<:Real}}) where {N} = true |
| 9 | +GeoInterface.geomtrait(::NTuple{N,<:Real}) where {N} = PointTrait() |
| 10 | +GeoInterface.ncoord(::PointTrait, geom::NTuple{N,<:Real}) where {N} = N |
| 11 | +GeoInterface.getcoord(::PointTrait, geom::NTuple{N,<:Real}, i) where {N} = getindex(geom, i) |
| 12 | + |
| 13 | +for i in 2:4 |
| 14 | + sig = NamedTuple{default_coord_names[1:i],NTuple{i,T}} where {T<:Real} |
| 15 | + GeoInterface.isgeometry(::Type{<:sig}) = true |
| 16 | + GeoInterface.geomtrait(::sig) = PointTrait() |
| 17 | + GeoInterface.ncoord(::PointTrait, geom::sig) = i |
| 18 | + GeoInterface.getcoord(::PointTrait, geom::sig, i) = getindex(geom, i) |
| 19 | +end |
| 20 | + |
| 21 | +# Custom coordinate order/names NamedTuple |
| 22 | +GeoInterface.isgeometry(::Type{<:NamedTuple{Keys,NTuple{N,T}}}) where {Keys,N,T<:Real} = all(in(default_coord_names), Keys) |
| 23 | +GeoInterface.geomtrait(::NamedTuple{Keys,NTuple{N,T}}) where {Keys,N,T<:Real} = PointTrait() |
| 24 | +GeoInterface.ncoord(::PointTrait, geom::NamedTuple{Keys,NTuple{N,T}}) where {Keys,N,T<:Real} = Base.length(geom) |
| 25 | +GeoInterface.getcoord(::PointTrait, geom::NamedTuple{Keys,NTuple{N,T}}, i) where {Keys,N,T<:Real} = getindex(geom, i) |
| 26 | +GeoInterface.coordnames(::PointTrait, geom::NamedTuple{Keys,NTuple{N,T}}) where {Keys,N,T<:Real} = Keys |
0 commit comments