Skip to content

Commit 162f960

Browse files
committed
Tables.jl interface is confusing
1 parent f243c40 commit 162f960

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
1717
SimpleSDMDatasets = "2c7d61d0-5c73-410d-85b2-d2e7fbbdcefa"
1818
SimpleSDMLayers = "2c645270-77db-11e9-22c3-0f302a89c64c"
1919
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
20+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
2021

2122
[compat]
2223
ArchGDAL = "0.9"

src/tables.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# We are a Tables.jl provider
2+
Tables.istable(::Type{T}) where {T <: SimpleSDMLayer} = true
3+
4+
# We access data in a layer by rows (they are provided by iteration)
5+
Tables.rowaccess(::Type{T}) where {T <: SimpleSDMLayer} = true
6+
7+
#
8+
function Tables.schema(layer::T) where {T <: SimpleSDMLayer}
9+
lon_type = eltype(longitudes(layer))
10+
lat_type = eltype(latitudes(layer))
11+
elm_type = eltype(l)
12+
colnames = [:longitude, :latitude, :value]
13+
coltypes = [lon_type, lat_type, elm_type]
14+
return Tables.schema(colnames, coltypes)
15+
end
16+
17+
function Tables.rows(layer::T) where {T <: SimpleSDMLayer}
18+
return layer
19+
end
20+
21+
function Tables.getcolumn(row, i::Int)
22+
if i == 1
23+
return row.first[1]
24+
elseif i == 2
25+
return row.first[2]
26+
end
27+
return row.second
28+
end
29+
30+
function Tables.getcolumn(row, nm::Symbol)
31+
if nm == :longitude
32+
return row.first[1]
33+
elseif nm == :latitude
34+
return row.first[2]
35+
end
36+
return row.second
37+
end

0 commit comments

Comments
 (0)