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

auto-convert option dicts to Dict{String, String} #542

Merged
merged 1 commit into from
Oct 22, 2023
Merged
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
19 changes: 10 additions & 9 deletions ext/RastersArchGDALExt/gdal_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,13 @@ end
function _process_options(driver::String, options::Dict;
_block_template=nothing
)
options_str = Dict(string(k)=>string(v) for (k,v) in options)
# Get the GDAL driver object
gdaldriver = AG.getdriver(driver)

# set default compression
if driver != "MEM" && !("COMPRESS" in keys(options)) && AG.validate(gdaldriver, ["COMPRESS=ZSTD"])
options["COMPRESS"] = "ZSTD"
if driver != "MEM" && !("COMPRESS" in keys(options_str)) && AG.validate(gdaldriver, ["COMPRESS=ZSTD"])
options_str["COMPRESS"] = "ZSTD"
end

# the goal is to set write block sizes that correspond to eventually blocked reads
Expand All @@ -463,23 +464,23 @@ function _process_options(driver::String, options::Dict;
block_x, block_y = string.(DA.max_chunksize(DA.eachchunk(_block_template)))
if driver == "GTiff"
# dont overwrite user specified values
if !("BLOCKXSIZE" in keys(options))
options["BLOCKXSIZE"] = block_x
if !("BLOCKXSIZE" in keys(options_str))
options_str["BLOCKXSIZE"] = block_x
end
if !("BLOCKYSIZE" in keys(options))
options["BLOCKYSIZE"] = block_y
if !("BLOCKYSIZE" in keys(options_str))
options_str["BLOCKYSIZE"] = block_y
end
elseif driver == "COG"
if !("BLOCKSIZE" in keys(options))
if !("BLOCKSIZE" in keys(options_str))
# cog only supports square blocks
# if the source already has square blocks, use them
# otherwise use the driver default
options["BLOCKSIZE"] = block_x == block_y ? block_x : 512
options_str["BLOCKSIZE"] = block_x == block_y ? block_x : 512
end
end
end
# if the input is unchunked we just use the driver defaults
options_vec = ["$(uppercase(k))=$(uppercase(string(v)))" for (k,v) in options]
options_vec = ["$(uppercase(k))=$(uppercase(v))" for (k,v) in options_str]

invalid_options = String[]
for option in options_vec
Expand Down
Loading