From fad508f33c723b60d3de1af2fb8d24612f4fb063 Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Fri, 9 Aug 2024 11:23:40 -0400 Subject: [PATCH] Use gdal.WarpOptions when merging rasters (#303) * While running notebooks on azure, I ran into a `zero positional` argument error from gdal.Warp when called from common.merge_rasters. In looking at the code, I changed to using gdal.WarpOptions which resolved the error. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- samgeo/common.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/samgeo/common.py b/samgeo/common.py index db617ef7..e7c69652 100644 --- a/samgeo/common.py +++ b/samgeo/common.py @@ -2992,16 +2992,20 @@ def merge_rasters( raise ImportError( "GDAL is required to use this function. Install it with `conda install gdal -c conda-forge`" ) + # Get a list of all the input files input_files = glob.glob(os.path.join(input_dir, input_pattern)) + # Prepare the gdal.Warp options + warp_options = gdal.WarpOptions( + format=output_format, dstNodata=output_nodata, creationOptions=output_options + ) + # Merge the input files into a single output file gdal.Warp( - output, - input_files, - format=output_format, - dstNodata=output_nodata, - options=output_options, + destNameOrDestDS=output, + srcDSOrSrcDSTab=input_files, + options=warp_options, )