Currently I am working with some satellite images (grib files) in pyqgis. As I want to work only with the cells in my study area, I need to clip the raster by a shapefile. I know I can do this by Raster tools in QGIS, but since I have a lot of rasters to work with, I wanted to use python and save time.

Perhaps somebody knows the pyqgis commands to do this?

I am new to QGIS and python.

1 Answer 1


The raster tool of QGIS uses GDAL commands

You can also use these GDAL commands (gdalwrap or gdal_translate) in a Python script, look at how to for loop a folder to batch clip rasters by polygon using python and QGIS or Extract raster windows from satellite imagery with GDAL and in pure Python Python GDAL/OGR Cookbook: Python Clip a GeoTiff with Shapefile

But you can do the same thing without PyQGIS or GDAL with the Python module PyShp: (Shapefile): GeospatialPython: Clip a Raster using a Shapefile

And you can also use Fiona and rasterio -> Warping images with rasterio

  • The GeospatialPython link you provide for a solution based on PyShp is wrong. That solution actually uses GDAL and no PyShp at all.
    – j08lue
    Jun 13, 2016 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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