I am trying to merge two tiles of the worldclim data in geotiff format, which I want to subsequently work with in the raster package in R.

When I use gdal's gdal_merge.py script: gdal_merge.py -v -o tmean1_06_16.tif tmean1_06.tif tmean1_16.tif

I get a merged file, but it seems as if the oceans have all been set to 0. see pic enter image description here

So I thought that the no data value is not set correctly when merging. Therefore I looked up the no data value in one of the original tiles with gdalinfo.

It seems the no data value is set to NoData Value=-3.39999999999999996e+38

So i tried to use that value when merging: gdal_merge.py -v -n -3.39999999999999996e+38 -o tmean1_06_16.tif tmean1_06.tif tmean1_16.tif

But that results in a file that seems to either have lost all information or have a legend that is shifted so far, that every temperature value is set to the max. Everything is a uniform green now. enter image description here

1 Answer 1


I think I may have figured it out.

If one resets the Nodata value in the original files to -9999 with: gdalwarp -dstnodata -9999 tmean1_16.tif tmean1_16_error999.tif

and then uses gdalmerge specifying both the input nodata value and the output nodatavalue: gdal_merge.py -v -n -9999 -a_nodata -9999 -o tmean1_06_16.tif tmean1_06_error999.tif tmean1_16_error999.tif

Then everything looks ok:

enter image description here

Your Answer

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

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