A previous question has established how to invoke QGIS's clip algorithm at the python console. I have done so and demonstrated that the method works satisfactorily on my data.

I would instead like to use this within a standalone script. To do so I've followed this to create the script below.

When I do so I get the following error message:

Unable to execute algorithm Wrong parameter value: ./path/to/highways.shp

Can anyone outline what is going on here?

import sys
import qgis.core
import qgis.core as qgc
import PyQt4.QtGui

# Initialise the application
app = PyQt4.QtGui.QApplication([])

# Prepare processing framework
from processing.core.Processing import Processing
import processing.tools

vlayer = qgc.QgsVectorLayer("./path/to/highways.shp", "highways", "ogr")

clayer = qgc.QgsVectorLayer("./path/to/boundaries.shp", "boundaries", "ogr")

processing.tools.general.runalg("qgis:clip", vlayer, clayer, "clip_from_script.shp")


Looking at the code that complains, it appears it is not getting an object (type) it expected. Make sure your layer loading works first —for starters I'd try absolute paths if you're not sure the working dir is where you expect it to be.

| improve this answer | |
  • Would seem to be the correct answer but a judicious print statement reveals the types of vlayer and clayer to be: <qgis._core.QgsVectorLayer object at 0x7f9457c1cc30> <qgis._core.QgsVectorLayer object at 0x7f9457c1ccc8>. Busy today but I'll try and add more analysis when I can get back to this. – lovelyzoo Nov 2 '15 at 15:12
  • Yeah, look at that getObject call, it's parent and param. – lynxlynxlynx Nov 2 '15 at 17:52

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.