Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 Quantum using the python console. Is this possible? If there are different ways to accomplish this, I'm open to suggestions.

Thank you! MH

share|improve this question
    
Out of interest how do you do it in ArcGIS? –  Nathan W May 14 '13 at 4:59
add comment

3 Answers

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.

share|improve this answer
add comment

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.

  • place all the rasters to be clipped in one directory
  • note the location of your clip polygon
  • 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: breaking gdalwarp command into sections

then I use excel's (or OpenOffice Calc) concatenate functions to generate the gdalwarp full command for each of my input rasters.

  • copy the output cells to a text file
  • save the text file to .bat (will look something like this): gdalwarp batch commands

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.

-BM

share|improve this answer
add comment

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

  • Download QGIS 2.0.1 stable and SAGA 2.0.8 or newer
  • Install the software, start QGIS and go to the Processing menu entry. Open the options and enable SAGA as provider if not already enabled
  • Start the Processing toolbox, search for the function "clip grid with polygon" and rightclick on it. A batch processing entry shows up. enter image description here
  • Batch clip the hell out of your data ;)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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