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).

1
  • 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. May 24, 2014 at 13:04

2 Answers 2

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
1
  • 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. May 24, 2014 at 13:03
-2

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

1
  • It is unfortunate that denormalization is so favorable.
    – ike
    May 22, 2014 at 13:11

Your Answer

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

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