From c1268bc7b789f856af50878afd922c1c31e484b8 Mon Sep 17 00:00:00 2001 From: JeroenVerstraelen Date: Fri, 22 Mar 2024 15:36:25 +0100 Subject: [PATCH] Issue #275 avoid throwing an error when raster in writeToDisk has 0 cols/rows --- .../openeo/geotrellis/netcdf/NetCDFRDDWriter.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/netcdf/NetCDFRDDWriter.scala b/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/netcdf/NetCDFRDDWriter.scala index 4dbc8ade..3e0f3be5 100644 --- a/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/netcdf/NetCDFRDDWriter.scala +++ b/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/netcdf/NetCDFRDDWriter.scala @@ -505,8 +505,16 @@ object NetCDFRDDWriter { val equalRasters = rasters.map(raster => if (raster.extent != maxExtent) raster.crop(maxExtent, CropOptions(clamp = false, force = true)) else raster ) - val aRaster = equalRasters.head - val rasterExtent = aRaster.rasterExtent + var aRaster = equalRasters.head + if (aRaster.tile.cols == 0 || aRaster.tile.rows == 0) { + logger.warn("At least one of the rasters in writeToDisk has 0 cols or rows. Trying to find a valid raster.") + val aRasterOption = equalRasters.find(raster => raster.tile.cols > 0 && raster.tile.rows > 0) + if (aRasterOption.isEmpty) { + throw new IllegalArgumentException("No valid raster data found.") + } + aRaster = aRasterOption.get + } + val rasterExtent: RasterExtent = aRaster.rasterExtent val intermediatePath = if (path.startsWith("s3:/")) {