I created some geoalgorithms with QGIS and I need to use them in a Python script. By saving the layer obtained in a file having a specific path, I do not have problems.
For example:
processing.runalg("modeler:esplodilinee", "buildings", "C:\prova\sides.shp")
lines = iface.addVectorLayer("C:\prova\sides.shp", "poligon sides", "ogr")
But I would not use a file, but rather a temporary variable, in order to re-use it within the specific script. The description of the algorithm suggests to me that:
ALGORITHM: esplodilinee
buildings <ParameterVector>
OUTPUT_ALGQGISEXPLODELINES_1 <OutputVector>
So, I thought to do something like this:
OUTPUT_ALGQGISEXPLODELINES_1 = processing.runalg("modeler:esplodilinee"
"buildings", None)
lines = processing.getObject(OUTPUT_ALGQGISEXPLODELINES_1)
But I get a mistake and not the desired results. Someone can help me?
If I correct my code as follow:
OUTPUT_ALGQGISEXPLODELINES_1= processing.runalg ("modeler: esplodilinee", "buildings", None) lines = processing.getObjectFromUri(OUTPUT_ALGQGISEXPLODELINES_1['OUTPUT'])
I get an error: "TypeError: 'NoneType' object has no attribute 'getitem' ". Do you suggest me why? Thanks again.
– Sara Gaudio Apr 24 '18 at 09:57
– Oscar Campo Apr 24 '18 at 10:03buildingsis a QgsVectorLayer object?Your model is working well outside the script? The input parameter is only one?
OUTPUT_ALGQGISEXPLODELINES_1isn't a dictionary but a None Type object. This because the runalg isn't working.... Try to run in the QGIS python console only the processing.runalg(...) untill it works :) – Oscar Campo Apr 24 '18 at 10:48prova=processing.runalg ("modeler:esplodilinee", buildings, None) lines = processing.getObject(prova['OUTPUT_ALGQGISEXPLODELINES_1'])
Thank you so much!
– Sara Gaudio Apr 24 '18 at 11:03