1

I have made a script for multiple clipping raster images with a shapefile as follow:

##Clip Multiple Rasters with Vector=name
##Utilities=group
##RASTERS=multiple raster
##VECTOR=vector
##OUTPUT=folder

import os
import processing

lddLrs = RASTERS.split(';')
for lyr in lddLrs:
    processing.runalg('saga:clipgridwithpolygon', str(lyr),VECTOR,OUTPUT+"/clip_"+ str(os.path.basename(str(lyr))))
    processing.load(str(OUTPUT + "/clip_" + str(os.path.basename(str(lyr)))))

It was working perfectly, but now I am having problems with the 'processing'

The error is the following:

2018-09-15T10:41:39 2   Uncaught error while executing algorithm
            Traceback (most recent call last):
              File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute
                self.processAlgorithm(progress)
              File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/plugins\processing\script\ScriptAlgorithm.py", line 378, in processAlgorithm
                exec((script), ns)
              File "<string>", line 13, in <module>
              File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 75, in runalg
                alg = Processing.runAlgorithm(algOrName, None, *args, **kwargs)
              File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 252, in runAlgorithm
                processing.alghelp(algOrName)
              File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 68, in alghelp
                print unicode(alg)
            IOError: [Errno 9] Bad file descriptor

Any suggestion to solve it?

1

Perhaps an additional parameter is required which is mentioned when you run:

import processing
processing.alghelp('saga:clipgridwithpolygon')

ALGORITHM: Clip raster with polygon
    INPUT <ParameterRaster>
    POLYGONS <ParameterVector>
    _RESAMPLING <ParameterSelection>
    OUTPUT <OutputRaster>

_RESAMPLING(Resampling method)
    0 - Nearest Neighbour
    1 - Bilinear Interpolation
    2 - Bicubic Spline Interpolation
    3 - B-Spline Interpolation

Try including the resampling parameter into your code, e.g.:

processing.runalg('saga:clipgridwithpolygon', str(lyr),VECTOR,0,OUTPUT+"/clip_"+ str(os.path.basename(str(lyr))))

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.