6

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()
2

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 Dec 26 '15 at 4:53

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.