2

I want to access the features of a temporary output to save certain geometric properties (in this case the length) in a variable.

Usually I would use:

path="C:\Users\..."
for files in os.listdir(path):
    if files.endswith(".shp"):
        layer = QgsVectorLayer(path+'/'+files, files, "ogr")
        features = layer.getFeatures()
        for f in features:
            geom = f.geometry()
            length = geom.length()

But since I'm now working with a temporary layer, created in a previous step in the script, I want to do something like this:

path="C:\Users\..."
for files in os.listdir(path):
    if files.endswith(".shp"):
        output=processing.runalg("qgis:pointstopath",path+'/'+files,"field1","field2","",None,None)
        features = output['OUTPUT_LINE'].getFeatures()
        for f in features:
            geom = f.geometry()
            length = geom.length()

How can I access the features of the temporary output['OUTPUT_LINE'] layer?

3

Try this:

output = processing.runalg("qgis:pointstopath",path+'/'+files,"field1","field2","",None,None)
layer = processing.getObject(output['OUTPUT'])
for feature in layer.getFeatures():
    # do something more

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.