I have 15 layers and I click on "show statistical summary" to calculate the same field for each layer.

Is there any method to calculate all of them at once rather than doing it one by one?

  • 3
    There is a tool called Basic statistics for fields that can be run as a batch process.
    – Matt
    Jan 12 at 19:23
  • i tried it , always gives me errors, it runs well when it's done one by one Jan 12 at 19:55
  • What is the statistics you want to calculate, sum/mean/? ?
    – BERA
    Jan 13 at 8:38

As was mentioned by @Matt there is corresponding algorithm for that i.e. "Basic statistics for fields", that can be launched from Python Console using PyQGIS.

Let's assume there are two layers 'groupe_layers' and 'groupe_layers_copy' with corresponding attribute tables, see image below.


My target field is the "AREA_HA" for which the basic statistics must be calculated.

Proceed with Plugins > Python Console > Show Editor and paste the script below

field_name = "AREA_HA" # target field

layers = ['groupe_layers', 'groupe_layers_copy'] # target layers

output_path = 'C:/TempDaten/' # location for storing temporal files

for layer in layers:
    processing.run("qgis:basicstatisticsforfields", {
        'INPUT_LAYER' : layer,
        'FIELD_NAME' : field_name,
        'OUTPUT_HTML_FILE' : output_path + layer + '.html'

Press Run script run script and get the output that will look like (openned in Chrome)


Afterwards you may parse your HTML files to get the desired values.

  • there are 15 layers and I want to show the length of each layer individually in one step rather than iterating the same process for each layer, I hope you get it Jan 13 at 9:12

You can try to merge the layers and then calculate the statistical summary

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.