Skip to content

Commit

Permalink
enable all virtual file systems (#486)
Browse files Browse the repository at this point in the history
* enable all virtual file systems

* make gdal_virt_fs const

---------

Co-authored-by: Max Freudenberg <[email protected]>
  • Loading branch information
maxfreu and Max Freudenberg authored Aug 3, 2023
1 parent b2e06e9 commit f36ba3f
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions ext/RastersArchGDALExt/gdal_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ const GDAL_Y_LOCUS = Start()
# drivers supporting the gdal Create() method to directly write to disk
const GDAL_DRIVERS_SUPPORTING_CREATE = ("GTiff", "HDF4", "KEA", "netCDF", "PCIDSK", "Zarr", "MEM"#=...=#)

# order is equal to https://gdal.org/user/virtual_file_systems.html
const GDAL_VIRTUAL_FILESYSTEMS = "/vsi" .* (
"zip",
"tar",
"gzip",
"7z",
"rar",
"curl",
"curl_streaming",
"s3",
"s3_streaming",
"gs",
"gs_streaming",
"az",
"az_streaming",
"adls",
"oss",
"oss_streaming",
"swift",
"swift_streaming",
"hdfs",
"webhdfs",
"stdin",
"stdout",
"mem",
"subfile",
"sparse",
)

# Array ########################################################################

function RA.FileArray(raster::AG.RasterDataset{T}, filename; kw...) where {T}
Expand Down Expand Up @@ -121,9 +150,10 @@ end

function RA._open(f, ::Type{GDALsource}, filename::AbstractString; write=false, kw...)
if !isfile(filename)
# Handle url filenames
# /vsicurl/ is added to urls for GDAL, /vsimem/ for in memory
if length(filename) >= 8 && filename[1:8] in ("/vsicurl", "/vsimem/")
# Handle gdal virtual file systems
# the respective string is prepended to the data source,
# e.g. /vsicurl/https://...
if length(filename) >= 8 && any(startswith.(filename, GDAL_VIRTUAL_FILESYSTEMS))
nothing
elseif RA._isurl(filename)
filename = "/vsicurl/" * filename
Expand Down

0 comments on commit f36ba3f

Please sign in to comment.