Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when passing unknown driver creation options #167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end

Write a GeoArray to `fn`. `nodata` is used to set the nodata value. Any `Missing` values in the GeoArray are converted to this value, otherwise the `typemax` of the element type
of the array is used. The shortname determines the GDAL driver, like "GTiff", when unset the filename extension is used to derive this driver. The `options` argument may be used
to pass driver options, such as setting the compression by `Dict("compression"=>"deflate")`. The `bandnames` keyword argument can be set to a vector or tuple of strings to set
to pass driver options, such as setting the compression by `Dict("compress"=>"deflate")`. The `bandnames` keyword argument can be set to a vector or tuple of strings to set
the band descriptions. It should have the same length as the number of bands.
"""
function write(fn::AbstractString, ga::GeoArray; nodata::Union{Nothing,Number}=nothing, shortname::AbstractString=find_shortname(fn), options::Dict{String,String}=Dict{String,String}(), bandnames=nothing)
Expand Down
44 changes: 42 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,50 @@ function setmetadata(ds::ArchGDAL.AbstractDataset, d::Dict{String})
end
end

function stringlist(dict::Dict{String})
const gtiffcreationoptions = [
"TFW",
"RPB",
"RPCTXT",
"INTERLEAVE",
"TILED",
"BLOCKXSIZE",
"BLOCKYSIZE",
"NBITS",
"COMPRESS",
"NUM_THREADS",
"PREDICTOR",
"DISCARD_LSB",
"SPARSE_OK",
"JPEG_QUALITY",
"JPEGTABLESMODE",
"ZLEVEL",
"ZSTD_LEVEL",
"MAX_Z_ERROR",
"MAX_Z_ERROR_OVERVIEW",
"WEBP_LEVEL",
"WEBP_LOSSLESS",
"JXL_LOSSLESS",
"JXL_EFFORT",
"JXL_DISTANCE",
"JXL_ALPHA_DISTANCE",
"PHOTOMETRIC",
"ALPHA",
"PROFILE",
"BIGTIFF",
"PIXELTYPE",
"COPY_SRC_OVERVIEWS",
"STREAMABLE_OUTPUT",
"GEOTIFF_KEYS_FLAVOR",
"GEOTIFF_VERSION",
"COLOR_TABLE_MULTIPLIER"
]

function stringlist(dict::Dict{String}; validate = true, validatelist = gtiffcreationoptions)
sv = Vector{String}()
for (k, v) in pairs(dict)
push!(sv, uppercase(string(k)) * "=" * string(v))
nk = uppercase(string(k))
validate && !(nk in validatelist) && @warn "Unrecognized key $nk. Should be one of $validatelist"
push!(sv, nk * "=" * string(v))
end
return sv
end
Expand Down