From fa97e68a6de76784beea64e3eea89770b39ba98b Mon Sep 17 00:00:00 2001 From: Paul Fouquet Date: Mon, 6 May 2024 11:02:11 +1200 Subject: [PATCH] feat: add option to create footprints Co-Authored-By: Victor Engmark Co-Authored-By: Alice Fage Co-Authored-By: Megan Davidson --- scripts/standardise_validate.py | 8 ++++++ scripts/standardising.py | 43 ++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/scripts/standardise_validate.py b/scripts/standardise_validate.py index cd0cee9fe..e0b38dd13 100644 --- a/scripts/standardise_validate.py +++ b/scripts/standardise_validate.py @@ -30,6 +30,13 @@ def main() -> None: help="The target EPSG code. If different to source the imagery will be reprojected", ) parser.add_argument("--gsd", dest="gsd", help="GSD of imagery Dataset", type=str, required=True) + parser.add_argument( + "--no-create-footprints", + dest="create_footprints", + help="Don't create footprints for each tile", + action="store_false", + default=True, + ) parser.add_argument("--cutline", dest="cutline", help="Optional cutline to cut imagery to", required=False, nargs="?") parser.add_argument("--collection-id", dest="collection_id", help="Unique id for collection", required=True) parser.add_argument( @@ -60,6 +67,7 @@ def main() -> None: arguments.source_epsg, arguments.target_epsg, arguments.gsd, + arguments.create_footprints, arguments.target, ) diff --git a/scripts/standardising.py b/scripts/standardising.py index 0123b5a65..cfb170609 100644 --- a/scripts/standardising.py +++ b/scripts/standardising.py @@ -34,6 +34,7 @@ def run_standardising( source_epsg: str, target_epsg: str, gsd: str, + create_footprints: bool, target_output: str = "/tmp/", ) -> List[FileTiff]: """Run `standardising()` in parallel (`concurrency`). @@ -68,6 +69,7 @@ def run_standardising( target_epsg=target_epsg, target_output=target_output, gsd=gsd, + create_footprints=create_footprints, cutline=cutline, ), todo, @@ -107,6 +109,7 @@ def standardising( source_epsg: str, target_epsg: str, gsd: str, + create_footprints: bool, cutline: Optional[str], target_output: str = "/tmp/", ) -> Optional[FileTiff]: @@ -212,25 +215,27 @@ def standardising( with TiffFile(standardized_working_path) as file_handle: if any(tile_byte_count != 0 for tile_byte_count in file_handle.pages.first.tags["TileByteCounts"].value): - # Create footprint GeoJSON - run_gdal( - [ - "gdal_footprint", - "-t_srs", - EpsgCode.EPSG_4326, - "-max_points", - "unlimited", - "-simplify", - str(get_buffer_distance(gsd_to_float(gsd))), - ], - standardized_working_path, - footprint_tmp_path, - ) - write( - footprint_file_path, - read(footprint_tmp_path), - content_type=ContentType.GEOJSON.value, - ) + if create_footprints: + # Create footprint GeoJSON + run_gdal( + [ + "gdal_footprint", + "-t_srs", + EpsgCode.EPSG_4326, + "-max_points", + "unlimited", + "-simplify", + str(get_buffer_distance(gsd_to_float(gsd))), + ], + standardized_working_path, + footprint_tmp_path, + ) + write( + footprint_file_path, + read(footprint_tmp_path), + content_type=ContentType.GEOJSON.value, + ) + write(standardized_file_path, read(standardized_working_path), content_type=ContentType.GEOTIFF.value) return tiff