From fc3704d72b1f8af2493bf193acc781fac313025e Mon Sep 17 00:00:00 2001 From: "Gregory H. Halverson" Date: Tue, 20 May 2025 15:43:57 -0700 Subject: [PATCH] fixing multi-band geotiff write --- Multi-raster.ipynb | 0 pyproject.toml | 2 +- rasters/raster.py | 8 ++++++-- rasters/version.txt | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 Multi-raster.ipynb diff --git a/Multi-raster.ipynb b/Multi-raster.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index 57bf20c..2f4dfbf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "rasters" -version = "1.5.2" +version = "1.5.3" description = "raster processing toolkit" readme = "README.md" authors = [ diff --git a/rasters/raster.py b/rasters/raster.py index a3d7115..4629cbf 100644 --- a/rasters/raster.py +++ b/rasters/raster.py @@ -1325,8 +1325,12 @@ def to_file( if exists(filename) and not overwrite: raise IOError(f"output file already exists: {filename}") - with rasterio.open(filename, "w", **profile) as file: - file.write(output_array, 1) + if len(self.shape) == 2: + with rasterio.open(filename, "w", **profile) as file: + file.write(output_array, 1) + else: + with rasterio.open(filename, "w", **profile) as file: + file.write(output_array) def to_geotiff( self, diff --git a/rasters/version.txt b/rasters/version.txt index 4cda8f1..8af85be 100644 --- a/rasters/version.txt +++ b/rasters/version.txt @@ -1 +1 @@ -1.5.2 +1.5.3