I am using 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?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
If you are interested using Python, a good documentation is available at GeospatialPython.com, here.
and clipraster.py source is here.
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):
- Convert the vector shapefile to a matrix which can be used as mask
- Load the geospatial image into a matrix
- Throw out any image cells outside of the shapefile extent
- Set all values outside the shapefile boundary to NODATA (null) values
- OPTIONAL: Perform a histogram stretch on the image for better visualization
- 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
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:
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
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