Raster Mosaicing and Clipping

This tutorial explores some basic raster operations in QGIS such as viewing, mosaicing and subsetting.

Overview of the task

We will download some public domain raster data for Brazil and view it in QGIS. Next, we will merge these into a single mosaic and clip it using a country boundary to get a single seamless dataset for the country.

Other skills you will learn

  • Searcing and downloading near real-time public domain satellite imagery.
  • Selecting a single feature from a vector layer and saving it to a new shapefile.

Get the data

We need Brazil country boundary to clip our raster. You can get the Admin 0 - Countries shapefile from Natural Earth.

NASA/GSFC, Rapid Response site has a good collection of near real-time satellite imagery. A good regional product is USDA Foreign Agricultural Service (FAS) subsets.. We will use 2km resolution FAS subsets for Brazil for this tutorial.

Here is how to search and download the revelant data.

  1. Open the South America region subsets. Find the Brazil subsets shown in the FAS Subsets section. Click on any one of them.
../_images/1140.png
  1. In the details page, click the 2km link under the product of your choice. Here we will download the NDVI product. Learn more about NDVI.
../_images/2100.png
  1. Click the Download GeoTIFF file link to download the raster image.
../_images/355.png

Repeat the process for all 7 FAS subsets for Brazil.

For convenience, you can directly download sample data used in this tutorial from links below.

ne_10m_admin_0_countries.zip

FAS_Brazil1.2013363.aqua.ndvi.2km.tif

FAS_Brazil2.2013363.terra.ndvi.2km.tif

FAS_Brazil3.2013363.aqua.ndvi.2km.tif

FAS_Brazil4.2013363.aqua.ndvi.2km.tif

FAS_Brazil5.2013363.aqua.ndvi.2km.tif

FAS_Brazil6.2013363.terra.ndvi.2km.tif

FAS_Brazil7.2013363.aqua.ndvi.2km.tif

Data Sources: [LANCE] [NATURALEARTH]

Procedure

  1. Open QGIS and go to Layer ‣ Add Raster Layer...
../_images/434.png
  1. Browse to the directory with the individual images. Hold down the Ctrl key and click on the image files to make a multiple selection. Click Open.
../_images/535.png
  1. You will see the images load up in the Table of Content on the left panel. Now let us create a single Mosaic image from all these individual images. Click on Raster ‣ Miscellaneous ‣ Merge.

Note

The Raster menu in QGIS comes from a core plugin called GdalTools. If you do not see the Raster menu, enable the GdalTools plugin from Plugins ‣ Manage and install plugins ‣ Installed. See Using Plugins for more details.

../_images/632.png
  1. In the Merge dialog, click Select… next to Input files and browse to the directory containing all the individual geotiffs. Keep holding Ctrl key and select all the. subsets. Now click Select… next to Output file and name the output as Brazil_mosaic.tif. At the bottom, check the box next to Load into canvas when finished. Click OK.
../_images/732.png
  1. You will get a pop-up message saying Processing complete, once the mosaic is created and loaded to the QGIS Canvas. You will see that the individual images and now combined and mosaiced into a single layer. You can now turn off individual layers by un-checking the box next to them.
../_images/829.png
  1. Another Raster operation you can do is to subset or crop an image. We can use a polygon from a vector layer to crop the raster to the exact shape. Let’s load the country polygons shapefile we downloaded from Natural Earth. Go to Layer ‣ Add Vector Layer.
../_images/929.png
  1. Select the ne_10m_admin_0_countries.zip file and click Open. When prompted to select the layer within the zip file, select ne_10m_admin_0_countries.shp.
../_images/1028.png
  1. Once the vector layer is loaded, we want to select and extract the polygon for Brazil. Select the Select Single Feature tool from the toolbar.
../_images/1141.png
  1. Click anywhere on the Brazil polygon and it will be selected.
../_images/1229.png
  1. Right-click the ne_10m_admin_0_countries layer and select Save Selection As….
../_images/1327.png
  1. Name your output as brazil_boundary.shp and make sure Add saved file to map box is checked. click OK.
../_images/1426.png
  1. You will see the Brazil boundary polygon now loaded in QGIS.
../_images/1525.png
  1. Now go to Raster ‣ Extraction ‣ Clipper.
../_images/1623.png
  1. Select the input file (raster) as Brazil_mosaic. Name the Output file as Brazil_mosaic_clipped. In the Clipping mode section, choose Mask layer. Select the newly created brazil_boundary as the mask layer. Check the box next to Load into canvas when finished. Click OK.
../_images/1721.png
  1. The new cropped layer will be loaded into QGIS. You will notice the black pixels surrounding the actual mosaic. Let’s remove that. Right-click on the Brazil_mosaic_clipped layer and select Properties.
../_images/1822.png
  1. Go to the Transparency tab, and add 0 as an Additional no data value.
../_images/1920.png
  1. Now you have a nice mosaic cropped to a country boundary that you can use in your project as a background layer or do further analysis on.
../_images/2016.png
comments powered by Disqus

This work is licensed under a Creative Commons Attribution 4.0 International License