From 8213f8efc5df3873975afeafd0d6e7c558c99fff Mon Sep 17 00:00:00 2001 From: Gedeon Muhawenayo Date: Fri, 2 Aug 2024 16:12:19 -0700 Subject: [PATCH 1/2] Fix set NODATA when clipping --- src/area_utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/area_utils.py b/src/area_utils.py index b89552e6..f03206d9 100644 --- a/src/area_utils.py +++ b/src/area_utils.py @@ -134,14 +134,21 @@ def load_raster( \n You need to project the map to the local UTM Zone \ (EPSG:XXXXX).""" ) + t_srs = input("Input EPSG Code; EPSG:XXXX:") - options = {"dstSRS": f"EPSG:{t_srs}", "dstNodata": 255} - gdal.Warp(f"prj_{in_raster_basename}", in_raster_basename, **options) - in_raster = f"prj_{in_raster_basename}" - return clip_raster(in_raster, boundary) + options = gdal.WarpOptions(dstSRS=f'EPSG:{t_srs}', dstNodata=255) + output_raster = f"prj_{in_raster_basename}" + gdal.Warp(output_raster, in_raster, options=options) + in_raster = output_raster + else: - print("Map CRS is %s. Loading map into memory." % src.crs) - return clip_raster(in_raster, boundary) + print("Map CRS is %s. Setting nodata value to 255." % src.crs) + options = gdal.WarpOptions(dstNodata=255) + output_raster = f"nodata_{in_raster_basename}" + gdal.Warp(output_raster, in_raster, options=options) + in_raster = output_raster + + return clip_raster(in_raster, boundary) def binarize( From 3a0d7534e5c1db077c730e33613819e90cb11e62 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 23:51:38 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/area_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/area_utils.py b/src/area_utils.py index f03206d9..b91408c8 100644 --- a/src/area_utils.py +++ b/src/area_utils.py @@ -134,9 +134,9 @@ def load_raster( \n You need to project the map to the local UTM Zone \ (EPSG:XXXXX).""" ) - + t_srs = input("Input EPSG Code; EPSG:XXXX:") - options = gdal.WarpOptions(dstSRS=f'EPSG:{t_srs}', dstNodata=255) + options = gdal.WarpOptions(dstSRS=f"EPSG:{t_srs}", dstNodata=255) output_raster = f"prj_{in_raster_basename}" gdal.Warp(output_raster, in_raster, options=options) in_raster = output_raster @@ -147,7 +147,7 @@ def load_raster( output_raster = f"nodata_{in_raster_basename}" gdal.Warp(output_raster, in_raster, options=options) in_raster = output_raster - + return clip_raster(in_raster, boundary)