In my map as you see below, I have my population by district.

I want to create 50 clusters with similiar sums of the population and by proximity. How I can achieve this?

For each cluster, I want the districts are next to each other (As you can see in yellow in the picture).


  • 1
    Have you taken a look at the various tool which pop up when you enter cluster in the search window of the tool box?
    – Erik
    Apr 5, 2019 at 6:16
  • yes, it seems they all used clustering with values but without considering the spatial proximity... Like this one : ekazakov.info/projects/abc_tutorial.html
    – Simon GIS
    Apr 5, 2019 at 6:20
  • DBSCAN definitely uses proximity.
    – Erik
    Apr 5, 2019 at 6:41
  • Yes, but will now not considerate the population factor. SO DBSCAN will only clusters in 50 base on distance...
    – Simon GIS
    Apr 5, 2019 at 6:48
  • @SimonGIS were you able to solve your problem ? Would you mind sharing how ?
    – YeO
    Jun 29, 2021 at 8:46

1 Answer 1


Not a full-fledged answer, but:

  1. Build an adjacency matrix of your polygons, to know which is adjacent to which. This may be done either through the R provide scripts, or Python, as far as I know there is no current implementation built in QGIS;
  2. Search via breadth-first search for the neighbours, and keep on checking whether you got to the population required.

You will need tweaks - you do not say if the population is given by a constant, or determined as a fraction of the overall population.


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