Skip to content

Commit

Permalink
feat: cog output (#60)
Browse files Browse the repository at this point in the history
* feat: change gdal command to COG

* fix: formatters

* fix: index not required

* fix: remove test code

* fix: typo

* fix: catch more errors using stderr
  • Loading branch information
MDavidson17 authored Jul 24, 2022
1 parent 01d941e commit 38ef527
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 8 additions & 3 deletions scripts/gdal_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ def run_gdal(command: List[str], input_file: str = "", output_file: str = "") ->
gdal_env["AWS_ACCESS_KEY_ID"] = credentials.access_key
gdal_env["AWS_SECRET_ACCESS_KEY"] = credentials.secret_key
gdal_env["AWS_SESSION_TOKEN"] = credentials.token
command.append(get_vfs_path(input_file))
input_file = get_vfs_path(input_file)
command.append(input_file)

if output_file:
command.append(output_file)

try:
get_log().debug("run_gdal", command=command_to_string(command))
proc = subprocess.run(command, env=gdal_env, check=True, capture_output=True)
proc = subprocess.run(command, env=gdal_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as cpe:
get_log().error("run_gdal_failed", command=command_to_string(command), error=str(cpe.stderr, "utf-8"))
raise cpe
get_log().debug("run_gdal_translate_succeded", command=command_to_string(command))
if proc.stderr:
get_log().error("run_gdal_error", command=command_to_string(command), error=proc.stderr.decode())
raise Exception(proc.stderr.decode())
get_log().debug("run_gdal_succeded", command=command_to_string(command))

return proc
20 changes: 19 additions & 1 deletion scripts/standardising.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,28 @@
"2",
"-b",
"3",
"-of",
"COG",
"-co",
"compress=lzw",
"-co",
"num_threads=all_cpus",
"-co",
"predictor=2",
"-co",
"overview_compress=webp",
"-co",
"bigtiff=yes",
"-co",
"overview_resampling=lanczos",
"-co",
"blocksize=512",
"-co",
"overview_quality=90",
"-co",
"sparse_ok=true",
]
run_gdal(command, file, tmp_file_path)
run_gdal(command, input_file=file, output_file=tmp_file_path)

# Upload the standardized file to destination
dst_file_path = os.path.join(dst_path, standardized_file_name).strip("/")
Expand Down

0 comments on commit 38ef527

Please sign in to comment.