Skip to content

Commit

Permalink
Made "source" to be a keyword argument were appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vikhliaev committed Jan 3, 2023
1 parent cb620be commit 845498e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/convenience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ _sourcetype(filename::AbstractString) = get(REV_EXT, splitext(filename)[2], GDAL
_sourcetype(filenames::NamedTuple) = _sourcetype(first(filenames))

# Internal read method
function _open(f, filename::AbstractString; kw...)
source=get(kw,:source,_sourcetype(filename))
function _open(f, filename::AbstractString; source=_sourcetype(filename), kw...)
_open(f, source, filename; kw...)
end
4 changes: 1 addition & 3 deletions src/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ function create(filename, T, A::AbstractRaster;
create(filename, T, dims(A); parent=parent(A), name, metadata, missingval, kw...)
end
function create(filename::AbstractString, T::Type, dims::Tuple;
lazy=true, parent=nothing, suffix=nothing, kw...
)
lazy=true, parent=nothing, suffix=nothing, source=_sourcetype(filename), kw...)
filename = _maybe_add_suffix(filename, suffix)
source=get(kw,:source,_sourcetype(filename))
create(filename, source, T, dims; lazy, kw...)
end
function create(filename::Nothing, T::Type, dims::Tuple;
Expand Down
2 changes: 1 addition & 1 deletion src/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function RasterStack(filename::AbstractString;
st = if haslayers(source)
crs = defaultcrs(source, crs)
mappedcrs = defaultmappedcrs(source, mappedcrs)
data, field_kw = _open(filename, source=source) do ds
data, field_kw = _open(filename; source) do ds
dims = dims isa Nothing ? DD.dims(ds, crs, mappedcrs) : dims
refdims = refdims == () || refdims isa Nothing ? () : refdims
layerdims = layerdims isa Nothing ? DD.layerdims(ds) : layerdims
Expand Down
7 changes: 3 additions & 4 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ Write an [`AbstractRaster`](@ref) to file, guessing the backend from the file ex
Keyword arguments are passed to the `write` method for the backend.
"""
function Base.write(
filename::AbstractString, A::AbstractRaster; kw...
filename::AbstractString, A::AbstractRaster; source=_sourcetype(filename), kw...
)
source=get(kw,:source,_sourcetype(filename))
write(filename, source, A; kw...)
end
Base.write(A::AbstractRaster) = write(filename(A), A)
Expand All @@ -26,13 +25,13 @@ Other keyword arguments are passed to the `write` method for the backend.
If the source can't be saved as a stack-like object, individual array layers will be saved.
"""
function Base.write(filename::AbstractString, s::AbstractRasterStack; suffix=nothing, ext=nothing, kw...)
function Base.write(filename::AbstractString, s::AbstractRasterStack; suffix=nothing, ext=nothing,
source=_sourcetype(filename), kw...)
if isnothing(ext)
base, ext = splitext(filename)
else
base = filename
end
source = get(kw,:source,_sourcetype(filename))
if haslayers(source)
write(filename, source, s; kw...)
else
Expand Down

0 comments on commit 845498e

Please sign in to comment.