|
| 1 | +# Implementation of trait based interface from https://github.com/JuliaGeo/GeoInterface.jl/ |
| 2 | + |
| 3 | +GeoInterface.isgeometry(::AbstractGeometry) = true |
| 4 | +GeoInterface.isgeometry(::AbstractFace) = true |
| 5 | +GeoInterface.isgeometry(::AbstractPoint) = true |
| 6 | +GeoInterface.isgeometry(::AbstractVector{<:AbstractGeometry}) = true |
| 7 | +GeoInterface.isgeometry(::AbstractVector{<:AbstractPoint}) = true |
| 8 | +GeoInterface.isgeometry(::AbstractVector{<:LineString}) = true |
| 9 | +GeoInterface.isgeometry(::AbstractVector{<:AbstractPolygon}) = true |
| 10 | +GeoInterface.isgeometry(::AbstractVector{<:AbstractFace}) = true |
| 11 | +GeoInterface.isgeometry(::Mesh) = true |
| 12 | + |
| 13 | +GeoInterface.geomtrait(::Point) = GeoInterface.PointTrait() |
| 14 | +GeoInterface.geomtrait(::Line) = GeoInterface.LineTrait() |
| 15 | +GeoInterface.geomtrait(::LineString) = GeoInterface.LineStringTrait() |
| 16 | +GeoInterface.geomtrait(::Polygon) = GeoInterface.PolygonTrait() |
| 17 | +GeoInterface.geomtrait(::MultiPoint) = GeoInterface.MultiPointTrait() |
| 18 | +GeoInterface.geomtrait(::MultiLineString) = GeoInterface.MultiLineStringTrait() |
| 19 | +GeoInterface.geomtrait(::MultiPolygon) = GeoInterface.MultiPolygonTrait() |
| 20 | +GeoInterface.geomtrait(::Ngon) = GeoInterface.PolygonTrait() |
| 21 | +GeoInterface.geomtrait(::AbstractMesh) = GeoInterface.PolyhedralSurfaceTrait() |
| 22 | + |
| 23 | +GeoInterface.geomtrait(::Simplex{Dim,T,1}) where {Dim,T} = GeoInterface.PointTrait() |
| 24 | +GeoInterface.geomtrait(::Simplex{Dim,T,2}) where {Dim,T} = GeoInterface.LineStringTrait() |
| 25 | +GeoInterface.geomtrait(::Simplex{Dim,T,3}) where {Dim,T} = GeoInterface.PolygonTrait() |
| 26 | + |
| 27 | +GeoInterface.ncoord(::GeoInterface.PointTrait, g::Point) = length(g) |
| 28 | +GeoInterface.getcoord(::GeoInterface.PointTrait, g::Point, i::Int) = g[i] |
| 29 | + |
| 30 | +GeoInterface.ngeom(::GeoInterface.LineTrait, g::Line) = length(g) |
| 31 | +GeoInterface.getgeom(::GeoInterface.LineTrait, g::Line, i::Int) = g[i] |
| 32 | + |
| 33 | +GeoInterface.ngeom(::GeoInterface.LineStringTrait, g::LineString) = length(g) |
| 34 | +function GeoInterface.getgeom(::GeoInterface.LineStringTrait, g::LineString, i::Int) |
| 35 | + return coordinates(g)[i] |
| 36 | +end |
| 37 | + |
| 38 | +GeoInterface.ngeom(::GeoInterface.PolygonTrait, g::Polygon) = length(g.interiors) + 1 # +1 for exterior |
| 39 | +function GeoInterface.getgeom(::GeoInterface.PolygonTrait, g::Polygon, i::Int) |
| 40 | + return i > 1 ? g.interiors[i - 1] : g.exterior |
| 41 | +end |
| 42 | + |
| 43 | +GeoInterface.ngeom(::GeoInterface.MultiPointTrait, g::MultiPoint) = length(g) |
| 44 | +GeoInterface.getgeom(::GeoInterface.MultiPointTrait, g::MultiPoint, i::Int) = g[i] |
| 45 | + |
| 46 | +function GeoInterface.ngeom(::GeoInterface.MultiLineStringTrait, g::MultiLineString) |
| 47 | + return length(g) |
| 48 | +end |
| 49 | +function GeoInterface.getgeom(::GeoInterface.MultiLineStringTrait, g::MultiLineString, |
| 50 | + i::Int) |
| 51 | + return g[i] |
| 52 | +end |
| 53 | + |
| 54 | +GeoInterface.ngeom(::GeoInterface.MultiPolygonTrait, g::MultiPolygon) = length(g) |
| 55 | +GeoInterface.getgeom(::GeoInterface.MultiPolygonTrait, g::MultiPolygon, i::Int) = g[i] |
| 56 | + |
| 57 | +function GeoInterface.ncoord(::GeoInterface.AbstractGeometryTrait, |
| 58 | + ::Simplex{Dim,T,N,P}) where {Dim,T,N,P} |
| 59 | + return Dim |
| 60 | +end |
| 61 | +function GeoInterface.ncoord(::GeoInterface.AbstractGeometryTrait, |
| 62 | + ::AbstractGeometry{Dim,T}) where {Dim,T} |
| 63 | + return Dim |
| 64 | +end |
| 65 | +function GeoInterface.ngeom(::GeoInterface.AbstractGeometryTrait, |
| 66 | + ::Simplex{Dim,T,N,P}) where {Dim,T,N,P} |
| 67 | + return N |
| 68 | +end |
| 69 | +GeoInterface.ngeom(::PolygonTrait, ::Ngon) = 1 # can't have any holes |
| 70 | +GeoInterface.getgeom(::PolygonTrait, g::Ngon, _) = LineString(g.points) |
| 71 | + |
| 72 | +GeoInterface.ncoord(::PolyhedralSurfaceTrait, ::Mesh{Dim,T,E,V} where {Dim,T,E,V}) = Dim |
| 73 | +GeoInterface.ngeom(::PolyhedralSurfaceTrait, g::AbstractMesh) = length(g) |
| 74 | +GeoInterface.getgeom(::PolyhedralSurfaceTrait, g::AbstractMesh, i) = g[i] |
0 commit comments