4

I'm new to QGIS and stuck with this task. Here's the data I'm working with:

The goal is to calculate the weighted population centroid for each county (image 1) based on the population density grid (image 2). In the end I want to export a list of the latitude/longitude coordinates of the centroids of all counties. Counties of Germany Population Grid

So far I was able to join the CSV data with the 1km-grid Shapefile. Then I've tried intersecting the two layers and playing around with the vector centroid function but nothing has worked. I have no clue how I can tackle this task and I couldn't find any solution online.

2

Short answer would be "Try Mean centroid(s) in the Processing Toolbox > Vector Analysis".

However, your dataset needs to get pre-processed before applying the tool.

(1) Pre-process (this part is specific to your data)

  • Let's assume you already have a Joined layer (1) by joining 1-square-kilometer grid and Population Data as CSV.
  • You would also have reprojected the VG250_Kreise county polygon (WGS84) to ETRS89 LAEA (named VG250_1Jan2011_ETRS89_LAEA_Kreise in my example (2)).
  • Then the first step is to create a Centroids (3) layer, converted from your Joined layer (1) which was a polygon layer.
  • Because the negative number (-1 for unknown) in your column "Einwohner" prevents to use it as the weight, we need to remove them using an expression (e.g. "Einwohner" > -1). In this example the output layername is Centroids_without_negative (4) .
  • Now, you need to attach the County ID (OBJECTID) to the above processed centroids layer. A picture attached below shows the Join attributes by location tool, which takes Centroids_without_negative (4) and VG250_1Jan2011_ETRS89_LAEA_Kreise (2) as inputs, with OBJECTID as the Field to add (you can add all the fields if you like).

enter image description here

(2) Main process

The above pre-processing would have given a new Joined layer (shown as brown points in the image below).

Start Mean coordinate(s) tool and set options like below:

  • Input layer: Joined layer (5)
  • Weight field: Column "Einwohner"
  • Unique ID field: OBJECTID

enter image description here

(3) Output and caveat

Click on Run button and you will see something like below:

enter image description here

  • The result Mean coordinate(s) (Weighted mean centroids) generally looks OK (such as (A) at upper-right).
  • However, you will find some centroids are not located within the polygon it should be in (see (B) at lower-right, pointed by a blue-arrow). These off-points would have to be processed separately.

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.