3

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?

9
  • 1
    Is the NoData value set for the raster? It's fine to say a value is nodata but unless it's actually been set as NoData it's not really NoData it's just an ignored value. If command line isn't working then change your directory to your GDAL install (you do have one don't you?) not just the GDAL that was installed with QGIS unless you're very familiar with CMD system variables. GDAL_Merge is a python script so you would need to have python installed as well, again not just the one with QGIS. What format is your raster that is overwriting? Jul 20, 2017 at 0:35
  • Yes, the NoDate value in the input files is set to -999. I got that using the Information command in the GDAL toolbox. I don't have a GDAL install that is separate to the one installed with QGIS. I guess I will need one, right? The implementation of the gdal_merge command in QGIS doesn't give the opportunity to specify the NoData value, and I am guessing that this is my problem. The raster format is GeoTIFF - same as the input file. It's ASTER data, so it's 32 bit. Jul 20, 2017 at 2:21
  • A method that I have used when mosaicing using GDAL is to build a VRT raster dataset with GDALBuildVRT which can then have the pyramids built and reviewed prior to exporting as a single image. You say that command line doesn't work, do you have GDAL installed or just QGIS? Are the TIFF images JPEG compressed? Jul 20, 2017 at 2:26
  • I tried building a VRT raster dataset in QGIS - I got the same problem with gaps in the mosaic, even specifying the NoData value. I don't have GDAL installed; just QGIS. I will have to figure out how to install GDAL. I'm running a Win 8.2 VM on a Mac using Parallels, so I have a choice of operating systems (generally use the Win build of QGIS because sometimes I have to work with ESRI personal geodatabases that need the Access libraries). I don't know whether the TIFF images have JPEG compression. Don't know how to find out. Jul 20, 2017 at 2:36
  • You can get the Windows binaries from gisinternals.com after installing you should be able to use the GDAL shell in the start menu to execute on the command line. Python is also needed for the python scripts python.org/downloads/windows and wiki.osgeo.org/wiki/OSGeo_Python_Library I can't give any reasonable explanation of why your NoData is being ignored but after installing GDAL you should be able to use GDALInfo to find the compression, if it's JPEG then the data is only close to NoData and you might need to run NearBlack gdal.org/nearblack.html Jul 20, 2017 at 2:51

1 Answer 1

1

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.

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.