1

processing.algorithmHelp('qgis:zonalstatistics') prints out:

----------------
Outputs
----------------

INPUT_VECTOR:  <QgsProcessingOutputVectorLayer>
        Zonal statistics

but I'd like to redirect the output to a CSV file with only the id column of the INPUT_VECTOR and the output of the Zonal statistics algorithm. Is this possible??

Is there some way to redirect the output?

1 Answer 1

0

Unless you modify the source code for the script, it will just save the attributes to the input vector file. A possible alternative could be to run the algorithm and then export the input layer as a csv file with only the fields you're interested in:

layer = iface.activeLayer()
output_path = 'path/to/output.csv'
zone_stats = ("id", "Count", "Sum", "Mean")
field_list = [layer.fields().indexFromName(fields.name()) for fields in layer.fields() if any(s in fields.name() for s in tuple(zone_stats))]
QgsVectorFileWriter.writeAsVectorFormat(layer, output_path, "UTF-8", driverName="CSV", attributes=field_list)
0

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.