I have a qgis vector representing a country.

This country countains many houses.

I want to join together every 600 houses starting from the bottom to the top with python and qgis.

I have a field called number_of_houses.

In the picture you can see the map and the number of houses in each cell.



  • Have you tried to dissolve your polygons (Vecteur > Outils de géotraitement > Regrouper )? – ArMoraer Mar 23 '16 at 15:13
  • yes, this tool dissolve polygons according to a common attribute. But me, I want to regroup them from the bottom to the top with a sum = 600. – Olfa Mar 23 '16 at 15:40

The problem is that it is not clear what you mean by regrouping from "bottom to top". How exactly do you want to cluster your voronoi polygons? You simply want the number of houses attribute of a cluster to add up to 600 right? The selection can be random ?

It seems that from your image you can easily do what you want to do manually - you don't need to use python, unless you have many more counties to perform the same task on.

Just select a bunch of polygons and use Vector > Analysis Tools > Basic Statistics to find the sum of the number of houses , and then add or subtract from your selection accordingly.

| improve this answer | |
  • Actually, I want to do that automatically. I want a script witch begining from the bottom of the country sum up the houses and when it reaches 600 , the script regroup them in one polygon and move on to the rest of houses and do the same task. – Olfa Mar 24 '16 at 7:46

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.