I am a total novice with GIS and using QGIS as that is what is available to me.

I have a vector layer of polygons (about 3500) and a raster layer of light intensity. What I'm working with looks like this:

enter image description here

I am trying to find the centroid of the polygons based on light intensity as a proxy for center of population in the polygon.

I know how to calculate the centroids of the polygons, but I am not sure how to include the values from the raster layer as weights.

I've read about clipping the raster layer based on a selection from the vector layer. I can clip a section from the raster and calculate the centroid based on the light intensity band, but I have no idea how to map that back to the original projection as the clipped raster only contains a GeoTransform (containing the coordinates for the top left corner of the rectangle that contains my polygon and some pixel extents), and a ProjectionRef (a string that I frankly understand little about).

I read Generate centroids for vector polygons based on raster and land-use data using QGIS, which makes sense. But looking at the interface for r.mapcalc in qgis I am at a loss of how to calculate the weighted centroid per polygon.

Logically I would assume that this kind of tool or method exists, but as I am a novice I don't know where to look and probably don't know how to ask properly either.

3 Answers 3


If you understand correctly you can create a grid, you choose a size that covers the smallest polygon ("vector grid" in toolbox) and then extracts the raster value using the grid, so use the tool "add raster values to features" in qgis toolbox. So you have a grid with raster values. Then you can extract the value of the raster using the centroid of the polygon (to compare)

We just have to think of a way to find the "luminous centroid of the polygon", I think you can do a thematic classification using a color ramp with grid values. This way you will have the most luminous points.

To get the brightest point of each polygon, you have to trim the grid with the values using the polygons and then sort them individually. then see what brightest value, filter it and save it as the centroid. I do not know if there is a fully automatic way of doing this.


The method I use for linking VIIRS lighting data to vector areas is as follows (assumes QGIS3):

  1. Make sure both the raster and vector layers are in the same CRS.

  2. Run the centroids tool on the vector layer (Menu > Vector > Geometry Tools > Centroids)

  3. Convert the lighting raster data to a vector point layer (Processing Sidebar > Vector Creation > Vectorize)

  4. Use the Join Attributes by Location tool (Processing Sidebar > Vector General > Join attributes by Location) to transfer the values to the original vector layer. Use the original vector layer as the Input Layer. Use the vectorized lighting data as the Join Layer. Choose Intersects for the Geometric Predicate.


Use this:

Raster -> Zonal statistics

The layers need to be in the same Coordinate Reference System.

  • 1
    Zonal statistics allows me to calculate mean, max, min, etc... but doesn't provide the option to calculate the weighted centroid. Unless I am missing something.
    – Grr
    Commented Oct 30, 2017 at 21:00

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.