Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
podcast
Filter by Categories
ArcGIS Pro
GDAL
GeoJson
Map
Map Tools
Maps
postgis
Python
QGIS
Uncategorized

Merging and Mosaicking Raster Data

Merging and Mosaicking Raster Data: Tips, Tricks, and Best Practices

Working with raster datasets is a fundamental aspect of geographic information systems (GIS) and remote sensing. Often, we need to combine multiple raster datasets to create a comprehensive, seamless image or to analyze a large area.

This process can involve merging adjacent rasters, mosaicking overlapping images, or handling different resolutions, projections, and NoData values. In this blog post, we will delve into the intricacies of merging and mosaicking raster data, providing practical tips and examples using popular GIS tools like GDAL and QGIS.

Want to stay ahead of the geospatial curve? Listen to our podcast!

Merging multiple rasters

Merging multiple raster datasets into a new raster dataset can be done using various GIS (Geographic Information System) tools and software like ArcGIS, QGIS, or GDAL. In this response, I will explain how to perform this task using two popular tools, GDAL (Geospatial Data Abstraction Library) and QGIS.

Merging raster datasets using GDAL:

You can use the gdal_merge.py utility to merge multiple raster datasets. This utility comes with the GDAL library. First, install GDAL if you haven’t already. Then follow these steps:

  • Step 1: Open the Command Prompt or Terminal on your computer.
  • Step 2: Navigate to the folder containing your raster files.
  • Step 3: Execute the following command to merge the raster datasets:
gdal_merge.py -o output_raster.tif input_raster1.tif input_raster2.tif input_raster3.tif

Replace output_raster.tif with the desired output file name and input_raster1.tif, input_raster2.tif, and input_raster3.tif with the names of the raster files, you want to merge. You can add more input files if necessary.

Merging raster datasets using QGIS:

If you prefer a GUI-based approach, you can use QGIS. Follow these steps:

  • Step 1: Install QGIS if you haven’t already.
  • Step 2: Open QGIS and go to ‘Layer’ > ‘Add Layer’ > ‘Add Raster Layer’ to import your raster datasets.
  • Step 3: Select the raster layers you want to merge in the Layers panel.
  • Step 4: Go to ‘Raster’ > ‘Miscellaneous’ > ‘Merge’ from the top menu.
  • Step 5: In the Merge window, check the box next to ‘Selected layers’ to use the layers you selected in the Layers panel.
  • Step 6: Set the output file by clicking the ‘…’ button next to ‘Output file’ and choose the location and name of the output raster dataset. Ensure that the file format is set to ‘GTiff’ or another appropriate format.
  • Step 7: Click ‘Run’ to start the merging process. The merged raster layer will be added to the Layers panel.

After completing either method, you will have a new raster dataset containing the merged data from your input raster datasets.

What if the two rasters have multiple bands?

When merging two or more raster datasets with multiple bands, you need to ensure that the input rasters have the same number of bands and that they represent the same type of data. The merging process will keep the band structure and merge the bands with the same indices from each input raster.

Using the same tools mentioned earlier (GDAL and QGIS), you can merge raster datasets with multiple bands.

Merging multi-band raster datasets using GDAL:

The process is the same as mentioned before. The gdal_merge.py the utility will handle multi-band raster datasets:

gdal_merge.py -o output_raster.tif input_raster1.tif input_raster2.tif input_raster3.tif

Replace output_raster.tif with the desired output file name and input_raster1.tif, input_raster2.tif, and input_raster3.tif with the names of the raster files, you want to merge. You can add more input files if necessary. The utility will merge the bands with the same index from each input raster.

Merging multi-band raster datasets using QGIS:

The process is the same as for single-band raster datasets:

  • Step 1: Import the raster datasets by going to ‘Layer’ > ‘Add Layer’ > ‘Add Raster Layer’.
  • Step 2: Select the raster layers you want to merge in the Layers panel.
  • Step 3: Go to ‘Raster’ > ‘Miscellaneous’ > ‘Merge’ from the top menu.
  • Step 4: In the Merge window, check the box next to ‘Selected layers’ to use the layers you selected in the Layers panel.
  • Step 5: Set the output file by clicking the ‘…’ button next to ‘Output file’ and choose the location and name of the output raster dataset. Ensure that the file format is set to ‘GTiff’ or another appropriate format.
  • Step 6: Click ‘Run’ to start the merging process. The merged raster layer will be added to the Layers panel.

In both methods, the output raster dataset will have the same number of bands as the input rasters, with each band being a merge of the corresponding bands from the input rasters.

What about the output pixel type?

When merging raster datasets, the output pixel type (or data type) is usually determined by the input raster datasets. However, you can explicitly specify the output pixel type if necessary. In both GDAL and QGIS, you can define the output pixel type during the merging process.

Specifying output pixel type using GDAL:

In the gdal_merge.py command, you can use the -ot option followed by the desired output pixel type. Here is a list of common pixel types:

  • Byte
  • UInt16
  • Int16
  • UInt32
  • Int32
  • Float32
  • Float64

To specify the output pixel type, modify the command like this:

gdal_merge.py -ot PixelType -o output_raster.tif input_raster1.tif input_raster2.tif

Replace PixelType with the desired output pixel type from the list above. For example, if you want the output to be 32-bit floating point:

gdal_merge.py -ot Float32 -o output_raster.tif input_raster1.tif input_raster2.tif

Specifying output pixel type using QGIS:

In QGIS, you can define the output pixel type in the ‘Merge’ tool window. Follow these steps:

  • Step 1: Open the ‘Merge’ tool by going to ‘Raster’ > ‘Miscellaneous’ > ‘Merge’.
  • Step 2: After selecting the input rasters and output file as described in the previous answer, click the ‘Advanced parameters’ dropdown menu.
  • Step 3: In the ‘Output data type’ dropdown, select the desired output pixel type. If you don’t select any option, the tool will use the input rasters’ pixel type by default.
  • Step 4: Click ‘Run’ to start the merging process.

By specifying the output pixel type, you can ensure that the merged raster dataset uses the desired data type for its pixel values. Make sure to choose an appropriate pixel type that can represent the range and precision of the data in your input rasters.

How do I handle rasters with different resolutions, projections, or extents?

When merging rasters with different resolutions, you should resample the input rasters to a common resolution before merging. Depending on your analysis needs, you can choose either the highest or lowest resolution or an intermediate resolution.

In GDAL, you can use gdalwarp to resample rasters:

gdalwarp -tr xRes yRes -r resampling_method input_raster.tif output_resampled_raster.tif

Replace xRes and yRes with the desired output resolution and choose a resampling method like near, bilinear, cubic, cubicspline, or lanczos.

In QGIS, use the ‘Raster’ > ‘Alignment’ > ‘Align Rasters’ tool to resample rasters to a common resolution.

Projections: All input rasters should have the same Coordinate Reference System (CRS) before merging. You can reproject rasters using GDAL or QGIS.

In GDAL, use gdalwarp to reproject:

gdalwarp -t_srs target_crs input_raster.tif output_reprojected_raster.tif

Replace target_crs with the desired output CRS, such as “EPSG:4326” or any other valid CRS identifier.

In QGIS, use the ‘Raster’ > ‘Projections’ > ‘Warp (Reproject)’ tool to reproject rasters to a common CRS.

Extents: When merging rasters with different extents, you can either crop or pad the input rasters to match a common extent before merging or allow the merge tool to automatically handle the extents.

What is the difference between merging and mosaicking rasters?

Merging: Merging refers to the process of combining multiple raster datasets into a single raster dataset by concatenating them. It is typically used when the input rasters have adjacent, non-overlapping extents. Merging does not account for any potential differences in pixel values or NoData values at the edges of the input rasters.

Mosaicking: Mosaicking is a more advanced process that involves blending or stitching together multiple raster datasets into a single, seamless raster dataset. Mosaicking is used when input rasters have overlapping extents or when you want to create a smooth transition between adjacent rasters by feathering, blending, or prioritizing pixel values based on specific criteria. Mosaicking can handle NoData values and may involve more complex algorithms to create a seamless output raster.

How can I deal with overlapping areas or NoData values in the input rasters?

Overlapping areas: When merging rasters with overlapping areas, you can handle them by prioritizing the input rasters based on specific criteria (e.g., more recent data, and higher data quality). In QGIS, the ‘Raster’ > ‘Miscellaneous’ > ‘Build Virtual Raster’ tool lets you control the order of the input rasters. The last raster in the list will have the highest priority in case of overlapping pixels.

NoData values: When merging or mosaicking rasters, you may need to deal with NoData values, which represent areas with missing or invalid data. In GDAL, you can use the -n and -a_nodata options in gdal_merge.py or gdalwarp to define the NoData value for input and output rasters.

In QGIS, when using the ‘Merge’ tool, you can define the NoData value in the ‘Advanced parameters’ section by setting the ‘Input pixel value to treat as “nodata”‘ and ‘Output pixel value to use for “nodata”‘ fields. This will help ensure that NoData values in the input rasters are handled correctly in the merged output raster.

If you are dealing with overlapping areas and NoData values while mosaicking, you can use more advanced techniques to blend or prioritize the input rasters. For instance, you can use a weighted average or another custom function to create a seamless transition between overlapping pixels.

In ArcGIS, the Mosaic To New Raster tool provides options for choosing the mosaic method, such as “LAST”, “FIRST”, “MIN”, “MAX”, “MEAN”, or “BLEND”, to determine how overlapping pixels are handled. Similarly, in QGIS, you can use the ‘Orfeo Toolbox’ plugin and its ‘Mosaic’ tool to create a mosaic with more control over how overlapping areas and NoData values are handled.

Remember that, when dealing with overlapping areas and NoData values, it’s essential to consider the characteristics of your input datasets and the specific requirements of your analysis to choose the most suitable approach for handling these issues.

About the Author
I'm Daniel O'Donohue, the voice and creator behind The MapScaping Podcast ( A podcast for the geospatial community ). With a professional background as a geospatial specialist, I've spent years harnessing the power of spatial to unravel the complexities of our world, one layer at a time.