Mosaicing rasters

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.

Getting ready

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.

How to do it...

This process is relatively straightforward and has a dedicated algorithm within the Processing Toolbox. Perform the following steps:

  1. Start QGIS.
  2. From the Plugins menu, select Python Console.
  3. Run the gdalogr:merge algorithm, specifying the process name, two images, a boolean to use the pseudocolor palette from the first image, a boolean to stack each image into a separate band, and the output filename:
    processing.runalg("gdalogr:merge","C:/qgis_data/rasters/Image2.tif;C:/qgis_data/rasters/Image1.tif",False,False,"/qgis_data/rasters/merged.tif")
    
  4. Verify that the merged.tif image has been created and displays the two images as a single raster within QGIS.

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset