2

I have hundreds of rasters that I want to mosaic in one raster. These rasters are squares surrounded by larger squares of NoData values. I am using gdal_merge.py to this and I can use the -n option to indicate a NoData value. My problem is that some rasters have no data values equal to -9999 and others have -3.40282347e+38.
When I indicate one of the values, for instance, -9999, the NoData values of the other images are preserved.

Is there a way to assign more than one NoData value or is there a way to assign to all the rasters the same NoData value?

I would prefer a solution with GDAL that I can run in hundreds of files without hundreds of clicks.

Vince
  • 20,017
  • 15
  • 45
  • 64
Na_Na_Na
  • 111
  • 9
  • 2
    Have you thought about doing a first pass of processing that resets the no data values to some consistent value, and then doing your mosaicking in a second pass of processing? – ycartwhelen Nov 30 '21 at 18:21
  • I wanted to do that, that was my second alternative, but I am nor sure how to do it – Na_Na_Na Dec 01 '21 at 15:37
  • gdal_calc might do the reclassifying no data values, and you could write a python script that does part 1 and then part 2 as a way to combine the two sections. Take a look at these two questions: https://gis.stackexchange.com/questions/245170/reclassifying-raster-using-gdal and https://gis.stackexchange.com/questions/163007/raster-reclassify-using-python-gdal-and-numpy?noredirect=1&lq=1 – ycartwhelen Dec 01 '21 at 15:42

1 Answers1

1

What I did at the end was not assign any NoData value, apparently, gdal_merge.py recognizes both numbers. I corroborated the results comparing the new raster with the original files and the areas with NoData values (-9999 or -3.40282347e+38) are now occupied by valid values from other rasters. I did this because I did not have enough time, but the solution proposed by ycartwhelen should be better to avoid mistakes.

Vince
  • 20,017
  • 15
  • 45
  • 64
Na_Na_Na
  • 111
  • 9