I'm writing a QGIS plugin using PyQGIS and I have a weird problem.
When executing following line of code:
processing.runandload("qgis:createpointsalonglines", r"Clipped", 1, 1, 0, r"memory:nodes")
Seems like Qgis doesnt allow me to output to a memory layer. The function works fine if I output to a an real (not-memory) layer, but I don't want that).
Why don't I want that? Beceause in that case, I have to create the layer first, and I need to have a path to save it..
The error:
However, with other processing.runandload functions (for example "qgis:clip"or qgis:orientedminimumboundingbox), it works fine with memory layer
For example,
I execute
processing.runandload("qgis:clip", "parallel", "polygon", r"memory:Clipped")
and
processing.runandload("qgis:orientedminimumboundingbox", "polygon", 1, r"memory:Oriented_MBBox")
without any problem, in the same program.
Anbybody has any idea why the problem occurs with the createpointsalonglines function?
The problem would also be solved if I outputed to a real layer. But in order to create a layer, you have to define the save path... But that doesnt seem like a good option, since I would then have to ask the user to give me a save path first.. Is there a way to create a layer somewhere without having to ask where? Maybe in the plugin folder? But how do I know the path to the plugin folder?
-
1Sorry! It did :)Kristof de Werdt– Kristof de Werdt2016年05月30日 13:32:57 +00:00Commented May 30, 2016 at 13:32
1 Answer 1
You can use None
as output parameter. Doing so, QGIS Processing creates a temporary vector file for you:
processing.runandload("qgis:createpointsalonglines", "Clipped" ,100,0,0,None)
Or:
res = processing.runalg("qgis:createpointsalonglines", "Clipped" ,100,0,0,None)
iface.addVectorLayer(res['output'],'my points','ogr')
In my case (on a GNU/Linux), the file is temporarily saved at:
/tmp/processing74861deb39ad40d2ad53cc9204ff2164/d2570e67f6444633824f27afbace50bd/output.shp
Explore related questions
See similar questions with these tags.