1

I wrote a QGIS plugin including the "gdalogr:cliprastermymasklayer" algorithm but get the following error message:

enter image description here

That's the code where I used the algorithm:

    def clipRasters(self):
    inputDir = self.getInputPath()
    outputDir = self.getOutputPath()
    for lyr in glob.glob(os.path.join(inputDir, "*xyz")):
        processing.run("gdalogr:cliprastermymasklayer", lyr, self.getVectorLayer(), 'none', True, False, 0,
                       outputDir + lyr)

Though, the error message is not specifically refering to my usage of the algorithm, I guess that's where the problem is.

Now, when I look at the following QGIS Dokumentation https://docs.qgis.org/3.4/en/docs/user_manual/processing_algs/gdal/rasterextraction.html#clip-raster-by-mask-layer, it seems that I could even give 9 arguments. Thus, why does it say in the error message that I can use only 6? Or does the message not refer to the number of arguments for the gdal algorithm?

2 Answers 2

3

All the parameters should be inside a single dictionary:

processing.run("gdalogr:cliprastermymasklayer", 
  { lyr, 
    self.getVectorLayer(), 
    'none', 
    True, 
    False, 
    0,
    outputDir + lyr
  })
0
1

There is a typo in the algorithm name.

You wrote gdalogr:cliprastermymasklayer instead of gdalogr:cliprasterbymasklayer

Your code:

def clipRasters(self):
inputDir = self.getInputPath()
outputDir = self.getOutputPath()
for lyr in glob.glob(os.path.join(inputDir, "*xyz")):
    processing.run("gdalogr:cliprastermymasklayer", lyr, self.getVectorLayer(), 'none', True, False, 0,
                   outputDir + lyr)

Should be:

def clipRasters(self):
inputDir = self.getInputPath()
outputDir = self.getOutputPath()
for lyr in glob.glob(os.path.join(inputDir, "*xyz")):
    processing.run("gdalogr:cliprasterbymasklayer", lyr, self.getVectorLayer(), 'none', True, False, 0,
                   outputDir + lyr)
1
  • 1
    Thanks Gob Tron, both comments solved one error but JGH's comment specifically resolved the error message I put in the question, so I choose his answer for the green check. But still Thanks to you as well, both answers are equally helpful in the end.
    – DGIS
    Oct 25, 2019 at 9:23

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.