GIS Tutorials >> Quantum GIS >> Beginner Quantum GIS Tutorials >> Masking a Raster in QGIS

GIS Programming Tutorials

GIS Theoretical Tutorials

GISTutor Newsletter

GISTutor Poll

How did you hear about us?

GISTutor Users Online

We have 19 guests online
Masking a Raster in QGIS
( 3 Votes )

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 Florida and we would like to limit the raster to be within the state boundaries of Florida.  We will use 2 layers, the original raster layer and a vector layer of the state of Florida. The image below illustrates this process.



Raster Masking Concept


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.


QGIS Raster Masking Clipper Dialog


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 Florida will have a value of 0 and will not be transparent.


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.



+1 #3 Philipp 2013-07-26 11:22
I seems you just clip the raster, you aren't masking it.
0 #2 2011-09-21 23:09
Hi Nilo Silva,

After doing a quick google search it seems that there maybe a conflict between the version of sip and python you have configured. I would suggest you try to download the latest version of QGIS, 1.7.0 Wroclaw and see if that resolves the issue.
+1 #1 2011-09-21 19:43
I tried "Making a raster in QGIS", but the following message apears:

Um erro ocorreu enquanto executava o seguinte código Python:

Traceback (most recent call last):
File "C:/PROGRA~1/QUANTU~4/apps/qgis/./python/plugins\GdalToo ls\tools\widget", line 27, in someValueChange d
self.emit(SIGNAL("valuesChanged(c onst QStringList &)"), self.getArguments())
File "C:/PROGRA~1/QUANTU~4/apps/qgis/./python/plugins\GdalToo ls\tools\doClip", line 105, in getArguments
return self.getArgsModeMask ()
File "C:/PROGRA~1/QUANTU~4/apps/qgis/./python/plugins\GdalToo ls\tools\doClip", line 143, in getArgsModeMask
if self.alphaBandCheck.isChecked():
TypeError: 'sip.methoddescripto r' object is not callable

I need help to resolve.

Add comment

Security code