3

I have a vector layer of polygons, and a raster layer with real numbers. I would like to get for each polygon, a 'centroid', not purely based on the geometry of the polygon (such as provided by Vector -> Geometry Tools -> Centroids), but based on the 'center of mass', where the equivalent of mass density is provided by the numbers in the raster layer.

This question seems related, but is ten years old, and hopefully an easier solution is available now.

1 Answer 1

2

I was looking to get the center of population for each municipality in France. I didn't find any answer on stack exchange, so I have made my own and share it as an answer to your question.

First step transform your raster to a point layer. Use "raster pixel to point" in QGIS to do it.

Then join by location your point layer and your polygon layer to get a ID field for every point in each polygon. enter image description here

Then use the tool "mean coordinate(s)" and choose your field use as weight and the field.

enter image description here

As a result you get your gravity center for every polygon, for my self it is the center of gravity of population for each municipality.

enter image description here

2
  • I ended up doing exactly that. However, converting to point layer, and processing that, was extremely slow in my case.
    – mspices
    Commented Aug 15, 2022 at 18:04
  • Indeed if your raster is big it could be long but as the QGIS core algo are optimized you can't find quicker solution. You may import your raster in a geopackage to get quicker conversion. Commented Aug 16, 2022 at 14:50

Your Answer

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

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