5

Using QGIS 3.10.1, I am attempting to rasterize some demographic polygons, and then apply a filter (Gaussian) to create a smooth/graduated surface. This works fine for some of my values (e.g. total population and housing units), but I am running into problems rasterizing averages (e.g. age and income). Average age, median income, and total population are all attributes of each demographic polygon.

When I rasterize the average age, for example, the values in the raster output are not weighted to the number of people, and this error gets magnified when I apply a filter. Imagine a feature that has 1000 people and an average age of 60 and the surrounding polygons have 10 people each and an average age of 20. When you use rasterize it creates a cell that is bigger than and contains all these features, but the rasterize algorithm only asks for the burn value and as a result, it averages the average age of all the features without regard to the number of people. As a result, the raster cell for that area erroneously shows a value of 22. If it was correctly weighted for the number of people it's value would be 59.

Because the area that I am looking at is a large area and includes urban polygons that are very small and rural ones that are very big it is inevitable that some cells span multiple polygons, and that there will be some overlap.

Are there any tools that can rasterize and apply a filter using 2 variables (a burn variable and a weight/quantity variable or can anyone recommend a workflow to address this issue?

One possible solution I've been exploring is to create duplicate geometries based on the total number of people. For example, a polygon with an average age of 40 with 10 people would get 1 polygon and a neighboring polygon with an average age 35 over 100 people would get 10 identical polygons so that when they go into the rasterize algorithm they are weighted appropriately. That could solve the rasterize issue, but I still would have the weighting problem when I apply the Gaussian filter.

Another way I am thinking about solving this issue is to rasterize/filter using aggregate data, and then use the raster calculator as the final step to divide the aggregate data by the total numbers of population or households.

0

This problem could be solved in so many different ways. Here I offer you a solution (with a model attached) that is as valid as your approaches.

The working example: enter image description here The polygons are labeled with the two parameters that you want to use as burn and weight: the first number is habitants and the second number is average age.

Here is an screenshot of the process: enter image description here

Let's say that you whant to rasterize this in cells of 200m, so the two first polygons on the left side are "calculated" together. The raster cell containing this two polygons should have a value of 66,66 average age (50*(1500)+100*(1500)).

What you can do here is the following process:

  1. Create a grid of the layer, in order to have an id that "match" poygons to a cell.
  2. Join by location the attributes of the layer to the grid. You should use one to many to get all the values for the same cell id.
  3. Calculate the weighted average age.

Use this function within field calcualtor:

sum( "AverAGE" * ("Hab" /sum("Hab", group_by:="id")),group_by := "id")

where:

  • AverAGE is the average age attribute (second number in my screenshot)
  • Hab is the number of people (first number in the screenshot).
  • id is the cell id (autogenerated in grid tool).

Whith this you will get something like: enter image description here

  1. Dissolve by id and rasterize. enter image description here

Here you can download the model and the layers used.

The model is not fully parametrized and you will need to edit the names of your attributes. Other than that it works and gives you a raster while asking just for a polygon layer and a cell size.

| improve this answer | |

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.