Skip to content

Commit

Permalink
convert options dict to Dict{String, String} (#542)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Freudenberg <[email protected]>
  • Loading branch information
maxfreu and Max Freudenberg authored Oct 22, 2023
1 parent 88af714 commit 1a61491
Showing 1 changed file with 10 additions and 9 deletions.
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

0 comments on commit 1a61491

Please sign in to comment.