Is it possible to calculate the sum of polygon areas based on whether or not it has a value in another column?

For example:

In column 2 I have the area of polygons. I want to calculate the area of all polygons that contain 'AG' in column 1 or all polygons that are IN column 1. But calculate them separately so I can get the total area of each type in column 1.

1 Answer 1


You may use the Statistics by categories algorithm from the Processing Toolbox and set these parameters:

  • Field to calculates statistics on: "Column 2" (or whatever fields that stores the area values);
  • Field with categories: "Column 1" (or whatever field that stores the polygon types).

You will obtain a CSV file containing statistics for the fields set (as min, max, mean, standard deviation, sum, count).

  • So I tried this but I keep getting an error that the "RuntimeError: Could not load layer XXXX.csv. Check the processing framework log to look for errors"
    – Aurust
    Jun 2, 2017 at 15:38
  • @Aurust, if I remember well, it works with shapefiles only. You didn't specify the file format. However, you may try converting the CSV to shapefile before running the proposed tool.
    – mgri
    Jun 2, 2017 at 15:42
  • The file I'm trying to run it on is a shapefile with polygons. The CSV the error is in regards to is the output CSV file from the algorithm.
    – Aurust
    Jun 2, 2017 at 15:50
  • @Aurust maybe there is some problems with path of the file? Are you sure there isn't' any blank space or special character in the filepath (both for input and output files)?
    – mgri
    Jun 2, 2017 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.