[GIS] Raster merge leaves gap where one file has no data

gdal-mergemergenodataqgisraster

So I gave up on using the Raster|Misc|Merge… command in QGIS because it always crashes. I tried using the merge tool from the GDAL/OGR Processing Toolbox instead. That runs OK, but it puts a gap in the mosaic where one of the input rasters contains no data values – looks like the no data values are over-writing the valid values from the other raster. Is there any way around this problem?

I assume that if you execute gdal_merge from a Windows command prompt then there are switches you can use to fine-tune the result which aren't available when you run it from inside QGIS. I tried that, but gdal_merge won't run this way on my machine, so I guess there's something wrong with the way this stuff is implemented in a Window QGIS installation. What to do?

Best Answer

You can run OsGeo4w just be searching for it in the Start menu - it is present with every QGIS Windows installation. Then you can make a .bat file with GDAL commands, which you can then run from the DOS-like shell. You can remove the NoData flag from a raster by using the gdal_edit.py command:

gdal_edit.py -unsetnodata yourfile.tif

I then also set my nodata values to zero using gdal_calc.py

gdal_calc.py -A yourfile.tif --outfile=yourfile-zeroed.tif --calc="A*(A>-9000)" --overwrite  --co COMPRESS=DEFLATE

The -co COMPRESS=DEFLATE option is there, because otherwise gdal_calc.py makes large uncompressed rasters. You can pick another compression method, of course.

Related Question