My algorithm needs a temporary layer in a QGIS processing script. I can use regular pyqgis api to create a temporary layer but want to know if there is a preferred and processing-specific way of doing it. Since processing already creates a temporary directory for the output, can it be used for creating another layer? Can I use processing.core.Vectorwriter or some other helper method?
Edit: I use the following right-now and looking for something more processing-specific and preferably writing to processing temporary dir instead of a memory layer.
templayer = QgsVectorLayer('Polygon?crs=%s' % input_layer.crs().authid(), 'temp', 'memory')
dataProvider = templayer.dataProvider()
templayer.startEditing()
dataProvider.addFeatures([features])
templayer.commitChanges()
templayer.updateExtents()
1 Answer 1
I've probably misunderstood you but using None
in a processing script creates a temporary output file which can also be used as an intermediate layer in scripts. From the docs:
For output data objects, type the file path to be used to save it, just as it is done from the toolbox. If you want to save the result to a temporary file, use
None
.
The temporary files are stored in a processing temporary directory. For my Windows 7 system, this is:
C:\Users\Me\AppData\Local\Temp
-
Thanks Joseph. I know that leaving the output to None creates a temporary layer. But as my question says, I want to know if there is a way to create an 'intermediate' temporary layer - not output. So this doesn't work for that.spatialthoughts– spatialthoughts2015年12月26日 04:53:52 +00:00Commented Dec 26, 2015 at 4:53