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](http://www.gistutor.com/images/stories/gistutor/qgis_raster_mask/raster_masking_concept.png)
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](http://www.gistutor.com/images/stories/gistutor/qgis_raster_mask/raster_masking_clipper_dialog.png)
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.
0 commentaires