Mosaicing rasters is the process of fusing multiple geospatial images with the same resolution and map projection into one raster. In this recipe, we'll combine two overlapping satellite images into a single dataset.
You will need to download the overlapping dataset from https://geospatialpython.googlecode.com/svn/overlap.zip if you haven't downloaded it from a previous recipe.
Place the two images in your /qgis_data/rasters/
directory.
This process is relatively straightforward and has a dedicated algorithm within the Processing Toolbox. Perform the following steps:
processing.runalg("gdalogr:merge","C:/qgis_data/rasters/Image2.tif;C:/qgis_data/rasters/Image1.tif",False,False,"/qgis_data/rasters/merged.tif")
merged.tif
image has been created and displays the two images as a single raster within QGIS.The merge processing algorithm is a simplified version of the actual gdal_merge
command-line utility. This algorithm is limited to the GDAL output and aggregates the extent of input rasters. It can only merge two rasters at a time. The gdal_merge tool has far more options, including additional output formats, the ability to merge more than two rasters at once, the ability to control the extent, and more. You can also use the GDAL API directly to take advantage of these features, but it will take far more code than what is used in this simple example.