# Joining attributes from more polygons into one

I have a polygon shapefile containing 1047 cities. In the attribute table I have population, area, and population density for each city.

My job is to merge all of the neighbouring cities (their boundaries) into one, so I should have smaller amount of polygons. This is what I get when I dissolve it and then multipart to single parts:

In the new, merged polygons, I should calculate possible population density based on the previous boundaries. Let's say that my formula is this:

• `Area_1_to_n=sum(area_i)` --> meaning the sum of polygons that are merged into one, for every merged polygon. This I can calculate in the field calculator, so it is not a problem.
• `Population_density_1_to_n=sum(population_density_i*area_i)/sum(area_i)` --> I should multiply population density with area for each polygon before merging, and then divide it by the number previously calculated.

The point is that I have to somehow calculate population density of the new polygons based on the smaller, previous polygons, if that makes sense.

Is there any way that I can do it in QGIS?

• What are considered neighbouring polygons? Are they touching, or within a specified distance, or the n closest?
– Matt
Mar 28, 2023 at 12:59
• They are touching. Mar 28, 2023 at 13:01
• Related: merge-adjacent-polygons-concatenate-attribute-values Not the same but very similar. There seem to be other questions that are also similar. In this sort of case you should reference similar questions and indicate how your question is different. Mar 28, 2023 at 18:57
• The problem is that the aggregate function that is mentioned in the related question does not provide the option to multiply values, as I have to multiply the values of population density from the polygons that are contained in the single dissolved polygons. Mar 29, 2023 at 8:56
• I discovered another problem: Multipart to singlepart option is not good because I should merge ONLY the the polygons of the cities that are touching. You can see in the picture that one city represents more areas/more polygons. In this case, the multipart to singlepart option merges the polygons that are touching, but creates more polygons for the same city that are isolated/not touching with any other polygon. I should somehow avoid this. Mar 29, 2023 at 10:46