From a2fa1b82ef35c56ef426b75b69145e52bc7f4508 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Tue, 13 Aug 2024 10:54:20 +0300 Subject: [PATCH] feat(CLI): add mask raster CLI function --- eis_toolkit/cli.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/eis_toolkit/cli.py b/eis_toolkit/cli.py index 090edbe2..05a33dfd 100644 --- a/eis_toolkit/cli.py +++ b/eis_toolkit/cli.py @@ -1516,6 +1516,30 @@ def surface_derivatives_cli( typer.echo(f"Calculating first and/or second order surface attributes completed, writing raster to {output_raster}") +@app.command() +def mask_raster_cli( + input_raster: INPUT_FILE_OPTION, + base_raster: INPUT_FILE_OPTION, + output_raster: OUTPUT_FILE_OPTION, +): + """Mask input raster using the nodata locations from base raster.""" + from eis_toolkit.raster_processing.masking import mask_raster + + typer.echo("Progress: 10%") + + with rasterio.open(input_raster) as raster: + with rasterio.open(base_raster) as base_rstr: + typer.echo("Progress: 25%") + out_image, out_meta = mask_raster(raster=raster, base_raster=base_rstr) + typer.echo("Progress: 75%") + + with rasterio.open(output_raster, "w", **out_meta) as dest: + dest.write(out_image) + typer.echo("Progress: 100%") + + typer.echo(f"Raster masking completed, writing raster to {output_raster}") + + @app.command() def reclassify_with_manual_breaks_cli( input_raster: INPUT_FILE_OPTION,