Raster Mosaicing and Clipping (QGIS3)

This tutorial explores basic techniques for working with rasters in QGIS such as mosaicing and subsetting.

Overview of the task

We will download elevation data for Sri Lanka in form of SRTM tiles, merge them and clip the resulting mosaic to the country boundary.

Other skills you will learn

  • Using the Hillshade renderer to visualize elevation data.

Get the data

Land Processes Distributed Active Archive Center (LP DAAC) provides NASA Shuttle Radar Topography Mission (SRTM) Global 1 arc second dataset as elevation tiles.

An easy interface to download tiles for a given area is the 30-Meter SRTM Tile Downloader by By Derek Watkins. Download the individual SRTM tiles covering Sri Lanka. Note that you will need a free Earth Data account to download the data.

../../_images/data115.png

We will also need the Admin 0 - Countries shapefile from Natural Earth.

For convenience, you may directly download a copy of the datasets from the links below:

N05E080.SRTMGL1.hgt.zip

N06E079.SRTMGL1.hgt.zip

N06E080.SRTMGL1.hgt.zip

N06E081.SRTMGL1.hgt.zip

N07E079.SRTMGL1.hgt.zip

N07E080.SRTMGL1.hgt.zip

N07E081.SRTMGL1.hgt.zip

N08E079.SRTMGL1.hgt.zip

N08E080.SRTMGL1.hgt.zip

N08E081.SRTMGL1.hgt.zip

N09E080.SRTMGL1.hgt.zip

ne_10m_admin_0_countries.zip

Data Source [SRTM] , [NATURALEARTH]

Procedure

  1. Open QGIS and locate the downloaded files in the Browser panel. Expand individual zip files to show the .hgt files. Hold the Ctrl key and select all individual files. Once selected, drag them to the canvas.

../../_images/1134.png
  1. You will see 11 individual layers loaded in the Layers panel and displayed in the canvas. We will merge these individual tiles into a single mosaic. Go to Processing ‣ Toolbox.

../../_images/2105.png
  1. Search and locate the GDAL ‣ Raster miscellaneous ‣ Merge tool. Double-click to launch it.

../../_images/349.png
  1. In the Merge dialog, click the button next to Input layers. Click Select All to select all individual layers.

../../_images/424.png
  1. As mentioned in the dataset layer details, the input data type is 16-bit signed integer. To maintain data integrity, we should keep the same data type for the merged layer. Select Int16 as the Output data type. Also the default output data format is GeoTiff. GeoTiff files can get very large if not compressed. Choose High Compression as the Profile. Click Run.

../../_images/524.png
  1. Once the processing finishes, the a new layer OUTPUT will be added to the Layers panel. In case the layer is not at the top of the stack, select it and drag it to the top of the Layers panel.

../../_images/623.png
  1. You will see that the OUTPUT layer contains the merged elevation data from the individual input tiles. The default visualization only shows the pixel values in the range from 0-255. But our data contains pixels with values -14 to 2371, resulting in a low contrast rendering. Let’s change it a better visualization. Click the Open the layer Styling panel button in the Layers panel.

../../_images/723.png
  1. In the Layer Styling panel, click the Render type dropdown and select Hillshade renderer. This rendering option is particularly well-suited for elevation data.

../../_images/822.png
  1. Another common operation when working with rasters is to clip a raster to your area of interest. For this tutorial, we will clip the merged layer to the country boundary for Sri Lanka. Locate the downloaded ne_10m_admin_0_countries.zip file and expand it. Drag the ne_10m_admin_0_countries.shp file to the canvas.

../../_images/923.png
  1. Select the newly added ne_10m_admin_0_countries layers in the Layers panel. Click the Select Features by area or single click button on the Attributes Toolbar. Once selected, click the polygon for Sri Lanka to select it.

../../_images/1030.png
  1. Keep the selection as it is and open Processing ‣ Toolbox. Search and locate the GDAL ‣ Raster extraction ‣ Clip raster by mask layer tool. Double-click to launch it.

../../_images/1135.png
  1. In the Clip Raster by Mask Layer dialog, set OUTPUT as the Input Layer. Select ne_10m_admin_0_countries as the Mask layer, and check the Selected features only checkbox. Enter 0.0000 as the Assign a specified nodata value to output bands. As before, choose High compression as the Profile. Click Run.

../../_images/1232.png
  1. A new layer OUTPUT will be added to the Layers panel. At this point, it may be hard to see the output because we have too many overlapping layers visible. Click the Manage Map Themes button in the Layers panel and choose Hide All Layers.

../../_images/1330.png
  1. Turn on only the latest OUTPUT layer and style it with the Hilshade renderer as done before.

../../_images/1427.png
  1. The merged and subsetted output elevation layer for Sri Lanka is ready.

../../_images/1525.png

If you want to report any issues with this tutorial, please comment below. (requires GitHub account)