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.

3
  • 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? Nov 30, 2021 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 1, 2021 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: gis.stackexchange.com/questions/245170/… and gis.stackexchange.com/questions/163007/… Dec 1, 2021 at 15:42

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.