4

I am writing a script to automate some processes which involved producing some layers like this:

Input -> Do sth on Input -> Layer A -> Do sth on Layer A-> Layer B -> Do sth on Layer B -> output

My approach is to save Layer A, B and the output as shapefile

However, layer A B are actually useless after the process is finished. I don't want to save them as shp but as temporary layer like below:

But I want to do it via PyQGIS

enter image description here

2
  • Do you use processing algorithme ? in a model processing ?
    – SIGIS
    Commented Dec 28, 2016 at 10:55
  • Use Layer A and B as memory layer
    – S. Thiyaku
    Commented Dec 28, 2016 at 11:16

1 Answer 1

5

You need to do something like this:

##output=output vector

from qgis.core import *
from PyQt4.QtCore import *

input = 'C:/path_to_the_file/test.shp'
layer = QgsVectorLayer(input, 'input' , 'ogr')

fill = processing.runalg("qgis:fillholes", input, 100000, None)

# Get the output from fill as object for further operations
layerA = processing.getObject(fill['Results'])


fill_2 = processing.runalg("qgis:fillholes", layerA, 100000, None)

# Get the output from fill_2 as object for further operations
layerB = processing.getObject(fill_2['Results'])


fill_3 = processing.runalg("qgis:fillholes", layerB, 100000, output)

In this example, I run the Fill holes algorithm for three times: in the first and the second operation, I save layerA and layerB as temporary layers, while in the last one I save the result to the disk.

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.