|Masking a Raster in QGIS|
This tutorial will guide you through the process of masking or clipping a raster layer based on a vector boundary layer. Most raster layers come in the format of a rectangle defined by the number of cells in its width and height with a value for every cell. However, when we make a map, we usually want to mask the layer according to some sort of boundary layer in the map.
For example, we have a raster layer located around the state of
Start by downloading the sample data here, which includes 2 GIS layers.
This tutorial requires you to have the GdalTools Plugin installed and enabled for QGIS. Learn how to use QGIS Plugins by following our tutorial “Using QGIS Plugins”.
Open QGIS and add your raster and vector layers. Under the Raster Menu (provided by the Gdaltools plugin), select “Clipper” to open the dialog window.
Set the Input file raster to be “usa_florida_raster”.
Name the output raster as a .GeoTIFF (.tif) file called “usa_florida_raster_clipped.tif” and store it in a desirable location on your computer.
Place a check next to “No data value” and leave it set to 0. This option will make all cells outside the state boundaries transparent with no data. If you do not check this option, all cells outside the state of
Under Clipping mode, select the “Mask layer” radio button and under the Mask layer dropdown menu, select our boundary layer “usa_florida”.
Place a check next to “Load into canvas when finished”, which will add the output to the layers.
You will notice the clipper dialog displays the command that will be run. The command used is the gdalwarp function with the cutline option.
Click OK to execute the clipper.
Once complete, click the “Close” button to dismiss the dialog.
The masked raster layer is added to the top of the layers manager.