1

I have a layer with a column conaining population values. I want to write an expression to compute in a new field the percentage of population each polygon has in relation to the total population.

I know I can use basic stats to get the SUM of area column, but I want an automatic process to repeat over several fields).

  • Thanks for the answers. I know I can export the data, do the calculations in Excel/LibreOffice and bring it back to QGis. However, I'm exploring a way to do everything inside QGis to create a model with Sextante. – Temporalista May 24 '14 at 13:04
1

It will depend on how your data is setup. But if, for example, you have 5 records in a table, with each record representing a different location with a different population, you could do one of two things:

1) Have a column representing the populations (A = state population; B = country population)
2) Enter the constant total population

Option 1 is better for larger datasets and datasets that do not have a constant total population. Either way, you will want to do the following:

1) (A / B) * 100
2) (A / constant value) * 100
  • Thanks for your answer. The problem is how to (automatically) compute "B" (or get the value of total population to reuse on a new formula). To give an idea, I have 8 datasets with 12 population columns each so I need to produce almost 100 new columns representing percentages. – Temporalista May 24 '14 at 13:03
-2

SELECT population, 100.0 * population/sum(population) OVER () FROM yourtable;

  • It is unfortunate that denormalization is so favorable. – ike May 22 '14 at 13:11

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.