In QGIS I would like to clip a raster precipitation layer using an admin boundary layer that is vector data. However the Geoprocessing tools seem to be usable only for vector data.

How can I clip this precipitation layer?

  • Did you really mean for "vector" to appear twice in this question?
    – whuber
    May 23, 2011 at 15:23
  • @whuber - not in particular...does it matter in this forum?
    – Kirk
    May 24, 2011 at 15:05
  • I couldn't make sense of the question without changing one of the "vector" to "raster." I think I get it now: you are saying you think the geoprocessing tools are only applicable when all elements are vector data. The confusion was that you explicitly say the boundary layer is in vector format, and as that is the immediate precedent, it makes the question ambiguous.
    – whuber
    May 24, 2011 at 15:19
  • 4
    I have the same problem as the original question - the clipping tool using the gdal plugin works, but it only clips in rectangles.....what if you need to clip it to something like a country border?
    – Matt
    Jun 14, 2012 at 16:53
  • convert vector to raster with 0/1 and use raster calculator with * "rasterLayer" see youtube.com/… Jul 7, 2020 at 19:07

5 Answers 5


Install the GDAL plugin and then use the Clipper Tool.
enter image description here

  • 12
    The "gdal tools" aka "raster tools" plugin is installed by default since qgis 1.5, if I'm not wrong. No need to install it manually. May 23, 2011 at 18:57
  • I found that this tool adds a band to the raster. It uses the command dstalpha.
    – BWill
    May 31, 2011 at 13:19
  • 2
    As Pablo has written, Clipper Tool is the answer. In qgis 1.7.0, the name of the plugin is "GdalTools". The tools (along with the "Clipper" we're looking for) are added to the Raster menu after enabling it with qgis plugin manager.
    – amp
    May 10, 2012 at 7:43
  • 1
    Please not that raster and vector data must be saved on disk in the same CRS. Simple png files and delimited text layers with CRS set in QGIS will not work.
    – AndreJ
    Dec 14, 2013 at 15:56

If you are interested using Python, a good documentation is available at GeospatialPython.com, here.

and clipraster.py source is here.


The Process:

Clipping a raster is a series of simple button clicks in high-end geospatial software packages. In terms of computing, geospatial images are actually very large, multi-dimensional arrays. Remote Sensing at its simplest is performing mathematical operations on these arrays to extract information from the data. Behind the scenes here is what the software is doing (give or take a few steps):

  1. Convert the vector shapefile to a matrix which can be used as mask
  2. Load the geospatial image into a matrix
  3. Throw out any image cells outside of the shapefile extent
  4. Set all values outside the shapefile boundary to NODATA (null) values
  5. OPTIONAL: Perform a histogram stretch on the image for better visualization
  6. Save the resulting image as a new raster.

I'd recommend using gdalwarp as you can increase the efficiency of the process.

For example, if you want to cut a raster inraster.tif with a shapefile extent.shp:

gdalwarp -cutline extent.shp -crop_to_cutline -of GTiff  -dstnodata 255 inraster.tif inraster_cropped.tif -co COMPRESS=LZW -co TILED=YES --config GDAL_CACHEMAX 2048 -multi

The last two parameters allows you to boost the process using:

  1. A multicore implementation.
  2. Setting the cache available to the function.
  • What are the reasons for using COMPRESS and TILED? Jun 21, 2020 at 16:31
  • Tiled is for a better visualisation experison and compress is to save storage space.
    – WAF
    Jun 26, 2020 at 1:59
  • This answer worked better than @Георгий Савельев using "Clip Raster by Mask Layer". Both clipped, however "gdalwarp" retains the metadata. I.e. The National Land Cover Dataset (NLCD) landcover geotiff comes with a "Color Table" nested in the metadata schema under the "Band" node. The table contains RGB + Alpha values for all 256 land class values (integers) For instance, Open Water = (70, 107, 159, 255). Gdalwarp can be called through the Command Line OR via Warp in QGIS directly: Raster-->Projections-->Warp. The latter may require Additional command-line parameters in the GUI (kind of). Jun 27 at 16:56

In QGIS 3.10.1 the developers put clipping of rasters in the Raster toolbar, in the Extraction section, it is now called "Clip Raster by Mask Layer". In the tool window there is an opportunity to select a CRS for input (or leave source CRS) and output rasters.

Definitely works with different CRS: I clipped a raster in Projected CRS with a mask layer in Geographic CRS.

NB! Mask layer is to be polygons

  • Thanks! Is it possible to clip a whole group of raster layers at once, rather than one by one? Apr 10, 2022 at 2:03
  • Works, but does not retain metadata. Refer to my answer in next Reply by @WAF using gdalwarp Jun 27 at 16:57
  • @NW_Photo_Laureate, this is strange. Raster > Clip Raster by Mask Layer calls gdalwarp, as you can see in the lowermost text field GDAL/OGR console call. So this has nothing to do with Clip Raster by Mask vs Wrap (Reproject). The problem is - which of gdalwarp parameters kills your metadata. Jun 29 at 9:31
  • @JohnNewman See Run as Batch Process... in the bottom of the Clip Raster by Mask Layer... window Jun 29 at 9:33

I'm not sure of how to do it in QGIS, however you may use another open source GIS software such as GRASS or GDALWarp to clip your raster. See keymirror and geographika answers below.

For an ArcGIS Desktop based solution, you may want to have a look at Clipping a raster using a polyline or polygon

Not the answer you're looking for? Browse other questions tagged or ask your own question.