4

I want to clip a raster by extent in QGIS with the python console. Here is the description given in the documentation. You have to use the following input parameter:

  • Input layer
  • Nodata value (no_data)
  • Clipping extent (projwin)
  • Additional creation parameter (extra)
  • output

The syntax is:

processing.runalg('gdalogr:cliprsterbyextent', input, no_data, projwin, extra, output)

I use the following data:

input = "C:/Users/....../inputraster.tif"

no_data= , , [I leave it empty]

projwin = 4278848, 3020676, 4297792, 3024646 [without " "]

extra = , , [I leave it empty]

output = "C:/Users/....../outputraster.asc"

I used these given examples in several variations, but I alway get a SyntaxError: invalid syntax.

5

You can get the correct syntax from the Processing | History and log after running the tool once from the toolbox:

processing.runalg("gdalogr:cliprasterbyextent",   
                  "C:/Users/anita/Geodata/qgis_sample_data/raster/SR_50M_alaska_nad.tif",
                  "",
                  "2001518.84322,3027531.34481,4007380.09563,4664339.34638",
                  "",
                  None)

enter image description here

This calls gdal_translate like this:

gdal_translate -of GTiff -projwin -6232946.6727 9275122.96868 6363148.43764 -735684.661767 
C:/Users/anita/Geodata/qgis_sample_data/raster/SR_50M_alaska_nad.tif "[temporary file]"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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