I have been able to batch clip rasters in one directory using python in ArcGIS.
However, I am not sure how to do the same in QGIS using the Python console.
Is this possible?
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
Although the question is already 4 months old and the OP probably already solved her problem:
Easy way how to do it in the new QGIS stable
QGIS uses gdal_translate utility to do the clipping. It is trivial to run gdal_translate from a shell script over files in a directory to clip all the rasters.
See this post for an example http://linfiniti.com/2010/11/batch-clipping-with-gdal-and-bash/
To make things easier, you can use the Raster -> Extraction -> Clipper tool to select your parameters. Then copy the gdal_translate command and use that in your script.
I'm still a newbie to this, so I have taken a longer approach to finding this answer - note that it only applies to clipping N rasters to a single simple ploygon. In my case, clipping 270 US precipitation .asc rasters to the state of Colorado.
in QGIS: Raster Menu > Extraction > Clipper -- load your first raster, output and clip polygon. Then copy the full gdalwarp command from the box in the bottom of the clip GUI. Should look like this:
gdalwarp -q -cutline D:/PeakGIS2/DATA/Colorado/STATE_WGS84.shp -crop_to_cutline -of GTiff D:/TEMP/US_PPT_4km/us_ppt_1980.10.asc D:/TEMP/CO_PPT_4km/PPT_CO_PRISM_1980_10.tif
Then, I created a spreadsheet with fields that break this command above into repeatable sections. In one of the fields, I list just the raster names, in the other fields i list my output names. Using excel helps to easily create numeric endings to your output raster name, like Grid_1, Grid_2 etc... just drag the cell down and it will automatically enumerate the ending.
The fields may look like this:
then I use excel's (or OpenOffice Calc) concatenate functions to generate the gdalwarp full command for each of my input rasters.
I then use the OSGeo4W command line in QGIS and run this .bat file which contains the 'gdalwarp' commands. This will run each command in the text file until it has exhausted the batch.
Like I said, it's a long-winded way of doing the job and I am positive there are several steps that could be saved here - but at least its a beginner's start.