From 660cda8fae437d69f5c87b22b6de73d69b152af5 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 19 Dec 2022 14:30:43 +1300 Subject: [PATCH 1/3] fix: force a alpha band on all imagery if a cutline is present --- scripts/gdal/gdal_preset.py | 13 ++++++++----- scripts/standardising.py | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/gdal/gdal_preset.py b/scripts/gdal/gdal_preset.py index ce396943e..630f88a4a 100644 --- a/scripts/gdal/gdal_preset.py +++ b/scripts/gdal/gdal_preset.py @@ -82,19 +82,22 @@ def get_gdal_command(preset: str) -> List[str]: return gdal_command -def get_cutline_command(cutline: str) -> List[str]: +def get_cutline_command(cutline: Optional[str]) -> List[str]: """ Get a "gdalwarp" command to create a virtual file (.vrt) which has a cutline applied and alpha added """ - return [ + gdal_command = [ "gdalwarp", # Outputting a VRT makes things faster as its not recomputing everything "-of", "VRT", - # Apply the cutline - "-cutline", - cutline, # Ensure the target has a alpha channel "-dstalpha", ] + + # Apply the cutline + if cutline: + gdal_command += ["-cutline",cutline] + + return gdal_command \ No newline at end of file diff --git a/scripts/standardising.py b/scripts/standardising.py index 932b84002..14be6cf44 100644 --- a/scripts/standardising.py +++ b/scripts/standardising.py @@ -99,10 +99,10 @@ def standardising(file: str, preset: str, cutline: Optional[str]) -> FileTiff: optimized_cutline = optimize_cutline(input_file, input_cutline_path) get_log().info("optimize_cutline", optimized_cutline=optimized_cutline, path=file) - if optimized_cutline: - target_vrt = os.path.join(tmp_path, str(ulid.ULID()) + ".vrt") - run_gdal(get_cutline_command(optimized_cutline), input_file=input_file, output_file=target_vrt) - input_file = target_vrt + + target_vrt = os.path.join(tmp_path, str(ulid.ULID()) + ".vrt") + run_gdal(get_cutline_command(optimized_cutline), input_file=input_file, output_file=target_vrt) + input_file = target_vrt command = get_gdal_command(preset) command.extend(get_gdal_band_offset(input_file)) From 7ceb9a238f949815dddeae567728b28afc801da4 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 19 Dec 2022 14:31:30 +1300 Subject: [PATCH 2/3] refactor: fixup lint --- scripts/gdal/gdal_preset.py | 8 ++++---- scripts/standardising.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/gdal/gdal_preset.py b/scripts/gdal/gdal_preset.py index 630f88a4a..813b02815 100644 --- a/scripts/gdal/gdal_preset.py +++ b/scripts/gdal/gdal_preset.py @@ -95,9 +95,9 @@ def get_cutline_command(cutline: Optional[str]) -> List[str]: # Ensure the target has a alpha channel "-dstalpha", ] - + # Apply the cutline - if cutline: - gdal_command += ["-cutline",cutline] + if cutline: + gdal_command += ["-cutline", cutline] - return gdal_command \ No newline at end of file + return gdal_command diff --git a/scripts/standardising.py b/scripts/standardising.py index 14be6cf44..00e5eca1d 100644 --- a/scripts/standardising.py +++ b/scripts/standardising.py @@ -99,7 +99,7 @@ def standardising(file: str, preset: str, cutline: Optional[str]) -> FileTiff: optimized_cutline = optimize_cutline(input_file, input_cutline_path) get_log().info("optimize_cutline", optimized_cutline=optimized_cutline, path=file) - + target_vrt = os.path.join(tmp_path, str(ulid.ULID()) + ".vrt") run_gdal(get_cutline_command(optimized_cutline), input_file=input_file, output_file=target_vrt) input_file = target_vrt From bee26258be2d3304bf77e477f4b73d7e35339a37 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 19 Dec 2022 14:34:14 +1300 Subject: [PATCH 3/3] refactor: missing import --- scripts/gdal/gdal_preset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gdal/gdal_preset.py b/scripts/gdal/gdal_preset.py index 813b02815..e2dc95d18 100644 --- a/scripts/gdal/gdal_preset.py +++ b/scripts/gdal/gdal_preset.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from linz_logger import get_log