2

I am trying to merge a total of 8 GeoTiff files (each one representing a single band) into a single TIF file using Gdal Merge in QGIS. The tool works, but does not allow me to select the order that these layers will be compiled in the output file.

This is problematic as the layer names are NOT conserved in the tool, and therefore it is difficult to tell one band from the other after merging (they are just named Band1, Band2). I have also tried running this in the CMD (since in QGIS you cannot even try to control layer order), but I couldnt get gdal_merge.py to work. The same for running gdal_merge via PyQGIS.

Here is what I mean by not being able to select layer order in the interface:

enter image description here

The problem is the same across QGIS 2.14 and 2.18.

  • What't the problem with running gdal_merge.py from the command line? – user30184 Mar 16 '18 at 13:22
  • I now got gdal_merge to work in the cmd, but since I'd want to merge multiple inputs (8) it is just less convenient. – 15Step Mar 16 '18 at 13:28
2

So one solution is in QGIS 3.0, where the exact same tool (GDAL Merge) allows to control the input layers' order by just dragging them above/below each other carefully. Oddly, if you drag a layer 'into' another it deletes it from the Multiple Selection box, so you must put it exactly between the layers you'd like it to appear.

2

If QGIS does not allow you to order the bands as you wish you can run gdal_merge.py from the command line http://www.gdal.org/gdal_merge.html.

Giving names for the bands requires another run with Python as answered in https://lists.osgeo.org/pipermail/gdal-dev/2015-February/041124.html

$ python

from osgeo import gdal
ds = gdal.GetDriverByName('GTiff').Create('test.tif',1,1,2)
ds.GetRasterBand(1).SetDescription('foo')
ds.GetRasterBand(2).SetDescription('bar')
ds = None


$ gdalinfo test.tif
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 1, 1
Coordinate System is `'
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,    1.0)
Upper Right (    1.0,    0.0)
Lower Right (    1.0,    1.0)
Center      (    0.5,    0.5)
Band 1 Block=1x1 Type=Byte, ColorInterp=Gray
  Description = foo
Band 2 Block=1x1 Type=Byte, ColorInterp=Undefined
  Description = bar
  • 1
    Helpful indeed, but is there a way to run gdal.merge in PyQGIS? Or in any Python environment, for that matter. – 15Step Mar 16 '18 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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