How can I cluster geographically 1886 polygons in QGIS knowing that I need 69 clusters with 27 polygons by cluster and one with only 23 polygons?

  • 2
    Can you explain a bit better how you need to cluster them? (A naive way of doing it would be to take the 27 first polygons in one cluster, the 27 next one in the next and so on...) Mar 12, 2020 at 20:58
  • If doing it that way, you have no guarantee that the clusters will get togheter geographically if that is what you need Mar 12, 2020 at 21:29
  • 1
    That's the issue, I need the clusters together geographically Mar 12, 2020 at 21:51
  • Can you make a screenshot of your data set and scetch what you try do achieve? - edit your question to insert it. Mar 13, 2020 at 5:39
  • please use the edit link to add the constraints that you need to apply
    – Ian Turton
    Mar 13, 2020 at 9:40

1 Answer 1


Vector analysis -> K-means clustering is a good tool for clustering features geographically. You can specify the required number of clusters.

  • Just out of curiosity, do you know if it can it cluster the way Angel asked for - 69 clusters with 27 polys and one with 23 if you set it up for clustering in 70 polygons. Or would it be 66 with 27 and four with 26? (I do not have any dataset with 1886 polys around to test it on...) Mar 13, 2020 at 13:12
  • @MortenSickel, I'm quite certain it cannot cluster exactly as Angel asked for. K-means minimizes within-cluster variance, and does to my knowledge not necessarily lead to evenly sized clusters.
    – Sam
    Mar 13, 2020 at 13:31

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.