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()
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 18, 2015 at 15:06

1 Answer 1

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
answered Dec 17, 2015 at 12:44
1
  • 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. Commented Dec 26, 2015 at 4:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.