2

I have a layer with several polygons making up a division together. They all have attributes with population.

Is it possible to add up the population in a merge so I don't have to use a calculator every time the data is updated?

  • What do you mean by division? How often is your data updated? I assume you want to automate this? Or is manually repeating several steps in QGIS ok? – LMB Oct 10 '18 at 6:14
3

An easy way to add or sum numbers is using sql in a virtual layer in QGIS.

Sum all numbers in mycolumn:

select sum(mycolumn) from mytable

Sum all numbers in mycolumn1 based on another column:

select sum(mycolumn1), mycolumn2 from mytable group by mycolumn2

Update:

You can also create a new geometry based off a value from another column:

select sum(mycolumn1), mycolumn2, st_union(geometry) as geometry 
from mytable group by mycolumn2

You can find the Virtual Layer editor in the Data Source Manager.

  • I think it's possible to add the geometry column to the query and get a merged polygon with the summed value in attribute table, do you have an exemple query with that ? – J.R Oct 10 '18 at 8:41
  • Updated the answer merging geometries together that have the same value in column mycolumn2 – Jakob Oct 10 '18 at 8:52
2

QGIS 3.0+

I like Virtual Layer approach, but currently having a trouble using it in QGIS 3.0-3.2 for some unknown reasons. Just in case you also have issue with Virtual Layer, I would suggest Aggregate function.

You can find it in Processing Toolbox | Vector geometry | Aggregate.

enter image description here

  1. Put the field you want (in my example it is val field) into the Input expression list.
  2. Select sum in the Aggregate function.
  3. Select Integer in the Type (as your data is population)
  4. Run the tool

enter image description here

Please note the output geometries are multi-part objects.

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