1

I'm facing a very strange issue from the module Processing using it as a standalone (not in the Qgis python console). I'm trying to create voronoi polygons from a points csv file. I can load my file without issue but the Processing.runAlgorithm always fail with " wrong number of arguments ". There are only 3 arguments described in the help.

#create uri
uri = "file://{}?delimiter={}&xField={}&yField={}".format(os.path.abspath(fichier.name),",","x","y")
#open file
layer = QgsVectorLayer(uri, "tmp", "delimitedtext")

# check
if not layer.isValid():
    print "Layer didn't load properly."
    print "Check your filename and the file integrity."

# UTF-8
layer.setProviderEncoding('UTF-8')

#feedback
print("File successfully loaded as " + layer.name() + " layer.")


Processing.runAlgorithm("qgis:voronoipolygons",layer,0.0, "test2.shp")

Traceback :

File successfully loaded as tmp layer.
Error: Wrong number of parameters
ALGORITHM: Voronoi polygons
    INPUT <ParameterVector>
    BUFFER <ParameterNumber>
    OUTPUT <OutputVector>

but it works from the Qgis python console :

mapcanvas = iface.mapCanvas()
layers = mapcanvas.layers()
processing.runalg("qgis:voronoipolygons",layers[0],0.0,"test.shp")

Output :

{'OUTPUT': 'test.shp'}

Even stranger, when i'm trying to add an unknown argument like :

Processing.runAlgorithm("qgis:voronoipolygons",layer,0.0, "test2.shp",0.0)

it returns :

File successfully loaded as tmp layer.
Error: Wrong parameter value: test2.shp

With adding 2 unknown arguments :

Processing.runAlgorithm("qgis:voronoipolygons",layer,0.0, "test2.shp",0.0,0.0)

TB :

File successfully loaded as tmp layer.
Error: Wrong number of parameters
ALGORITHM: Voronoi polygons
    INPUT <ParameterVector>
    BUFFER <ParameterNumber>
    OUTPUT <OutputVector>

Looks like there is a forth argument ... Any idea ?

1 Answer 1

1

Syntax is:

runAlgorithm(algOrName, onFinish, *args, **kwargs). 

Just set None to onFinish argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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