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

feat: cog output #60

Merged
merged 6 commits into from
Jul 24, 2022
Merged
Changes from 1 commit
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
Next Next commit
feat: change gdal command to COG
MDavidson17 committed Jul 19, 2022
commit bef5d27622d8f57b894eeb76708aec86b53ca6b6
10 changes: 7 additions & 3 deletions scripts/gdal_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import subprocess
from typing import List
from typing import List, Optional

from aws_helper import get_bucket_name_from_path, get_credentials, is_s3
from linz_logger import get_log
@@ -30,7 +30,7 @@ def command_to_string(command: List[str]) -> str:
return " ".join(command)


def run_gdal(command: List[str], input_file: str = "", output_file: str = "") -> "subprocess.CompletedProcess[bytes]":
def run_gdal(command: List[str] = [], input_file: str = "", output_file: str = "", input_file_index: Optional[int] = None) -> "subprocess.CompletedProcess[bytes]":
"""Run the GDAL command. The permissions to access to the input file are applied to the gdal environment.

Args:
@@ -53,7 +53,11 @@ 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)
if input_file_index:
MDavidson17 marked this conversation as resolved.
Show resolved Hide resolved
command.insert(input_file_index, input_file)
else:
command.append(input_file)

if output_file:
command.append(output_file)
20 changes: 19 additions & 1 deletion scripts/standardising.py
Original file line number Diff line number Diff line change
@@ -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",
"biggtiff=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, input_file_index=17)

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