-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSTACExt.jl
More file actions
37 lines (31 loc) · 981 Bytes
/
STACExt.jl
File metadata and controls
37 lines (31 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module STACExt
using SpeciesDistributionToolkit
using STAC
import Downloads
function SimpleSDMLayers.SDMLayer(asset::STAC.Asset; store::Bool=true, kwargs...)
# Step 1 - get the asset url
asset_url = asset.data.href
# Step 2 - download the file if required
filepath = tempname()
if store
savedir = joinpath(SimpleSDMDatasets._LAYER_PATH, "STAC", string(hash(asset_url)))
if !ispath(savedir)
mkpath(savedir)
end
fname = split(asset_url, "/")[end]
filepath = joinpath(savedir, fname)
if !isfile(filepath)
Downloads.download(asset_url, filepath)
end
else
Downloads.download(asset_url, filepath)
end
# Step 3 - load the file
L = SDMLayer(filepath; kwargs...)
# Return
return L
end
# TODO layers method for a STACCatalog (or provides?)
# TODO layers method for a collection within a STAC
# TODO overload some SimpleSDMDatasets methods for times?
end