Skip to content

Commit

Permalink
feat: add option to create footprints
Browse files Browse the repository at this point in the history
Co-Authored-By: Victor Engmark <[email protected]>
Co-Authored-By: Alice Fage <[email protected]>
Co-Authored-By: Megan Davidson <[email protected]>
  • Loading branch information
4 people committed May 6, 2024
1 parent 0b6158b commit fa97e68
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
8 changes: 8 additions & 0 deletions scripts/standardise_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -60,6 +67,7 @@ def main() -> None:
arguments.source_epsg,
arguments.target_epsg,
arguments.gsd,
arguments.create_footprints,
arguments.target,
)

Expand Down
43 changes: 24 additions & 19 deletions scripts/standardising.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down Expand Up @@ -68,6 +69,7 @@ def run_standardising(
target_epsg=target_epsg,
target_output=target_output,
gsd=gsd,
create_footprints=create_footprints,
cutline=cutline,
),
todo,
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa97e68

Please sign in to comment.