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
Answer
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.
No comments:
Post a Comment