Skip to content

Commit

Permalink
fix: force a alpha band on all imagery if a cutline is present (#264)
Browse files Browse the repository at this point in the history
* fix: force a alpha band on all imagery if a cutline is present

* refactor: fixup lint

* refactor: missing import
  • Loading branch information
blacha authored Dec 19, 2022
1 parent 78e55eb commit dab4565
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions scripts/gdal/gdal_preset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

from linz_logger import get_log

Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions scripts/standardising.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit dab4565

Please sign in to comment.