[GIS] Merging tif images into a single GeoTiff with QGIS

geotiff-tiffmergeqgis

For this example, I have 3 tif images that are tiles. They fit together to form a single image.

I load the 3 images into QGIS and it merges them directly and I see my completed image.

The problem is I need to export it to a single geotiff image. I can only get it to export one of the layers (tiles). I need to essentially merge the layers into a single layer and then export that layer (or something like that)

Best Answer

The tutorial in the answer posted by Venug uses the Raster > Miscellaneous > Merge functionality. What I don't like about that method is that it requires you to find the files you want to merge in your file system. This can be tedious in a directory with hundreds of files. I prefer to use the Processing tools, which use the layers as inputs.

Here I have an example with three rasters loaded. I will demonstrate how to merge these using the QGIS Processing algorithms.

Example with three rasters

Step 1: Convert paletted files to RGB or RGBA

If your TIF files are paletted, you will need to first convert them to RGB or RGBA. If they are already in one of those formats, you can skip this step. If you are not sure, open the layer properties window and click on the Style tab. If it's paletted, it should say so next to 'Render type'. If it's multiband color, singleband grayscale or singleband pseudocolor, it should merge just fine without conversion and you can skip ahead to step 2.

Paletted example

From the menu, choose 'Processing > Toolbox...'. This should open a panel next to the map canvas. Find the translate algorithm in the Processing toolbox

Click the drop-down list at the bottom to select 'Advanced interface'. In the search box at the top, type 'translate'. Double-click the translate function under the GDAL algorithms.

To speed things up, click the 'Run as batch process...' button on the top right. The batch screen will load. Click the ellipsis button (...) In the 'Input layer' column on the first row. In the context menu that opens, choose 'Select from open layers'. Click 'Select all', then 'OK'.

Select layers

Click the drop-down in the Expand column for each row, and select 'rgba'.

Set Expand to rgba

In the Converted column, click the ellipsis next to the field in the first row, and choose a directory and file name for the converted images. You can give it a base name, say 'convert', and when it prompts you for autofill options, choose 'Fill with numbers'. This will auto-name the output files with incremental numbers. Click the 'Run' button to convert the images.

Choose output file names for converted images

Step 2: Merge raster layers

In the same way that you searched for the Translate algorithm, type 'merge' in the Processing search box and double-click on 'Merge' under the GDAL algorithms. Click the ellipsis next to the 'Input layers' selector, select the layers you want to merge (the 'Converted' layers if you followed step 1, otherwise 'Select all') and click 'OK'. If you'd like to save the merged file, click the ellipsis next to the 'Merged' selector and choose an output file name and location. Click 'Run' to start the merging process.

Merge layers

The result should look something like this:

Result

If there were some areas not covered by the input files, as in this example, you may see black pixels in the gaps. This is because you can't set a default nodata value with the Processing merge function (at least as of QGIS 2.12.2). You will need to either set an extra nodata value in the layer style, or, more permanently, run Translate again on the merge file and set the nodata value to be 0. The black areas will then be transparent again.

Related Question