Generically, the problem is to take small polygons (HUC 12 watersheds intersected with counties and/or minor civil divisions) and disolve those into larger polygons that meet a couple of criteria:

  1. Population ~ state population divided by the number of districts to be assembled.
  2. Minor Civil Divisions (or in the case of high-density areas, census blocks/block groups) remain in the same district. (I can ensure this by pre-disolving some of the original polygons into slightly larger polygons.)
  3. Compactness -- resulting district polygons should have ratios of first- and second-longest axes being close to 1 (or some other measure?)
  4. Preference to add HUCs upstream to add population, rather then add rather then next door. Or, at minimum, I would want to stay within the same next-level watershed (i.e. if I am adding two HUC 12s to form a district, they must be in the same HUC 10).

I have a general idea that I should start with the largest HUC I can (e.g., if no HUC 12 will stand alone, I work with HUC 10s), but where do I start? I could start at the downstream end of the state border for each HUC 10, for example, then add upstream (or adjacent same-order) HUC 10sstate boundaries, perhaps, then move upstream from each one HUC12 at a a time. I would like to have code do all the adding, searching, comparing, etc.

I wonder if anyone has tried something similar for this or other purposes. It's a generic QGIS problem, but my interest in it now is that Virginia has put redistricting into the hands of court-ordained pair of individuals, and I'd like to float the idea that we could be representing groups of people in an ecologically meaningful way, rather than ending up with political gerrymanders.

I know it won't happen this round, but I'd like to start a conversation about what should unite people.

1 Answer 1


There is a QGIS redistricting plugin which would allow you to do this manually (I wrote it, just stumbled across this.)

If you wanted to do this manually using the plugin, I would recommend working at the census block level, creating a "DISTRICT" column, assigning one district per watershed - which would give you too many districts - and then merging adjacent districts which are together below the population margin. You could do this relatively easily manually using a spatial join to map the watersheds to the blocks and then using the plugin's select tool to merge watersheds together (you may want to create a duplicate "WATERSHED_ID" column as well once you start merging districts together.

If you want to do this programatically, it's more difficult and you'd probably need to write pyqgis code to loop through the neighbours of each polygon and then pick the most suitable candidate.

My guess having done both is that it's going to be less time consuming to do this manually, at a census block level, using a spatially joined watershed-level geography than training a python script to do it automatically.

Hope this provides at least a little bit of guidance.

  • Thanks. I'll check out that plugin. Jan 21, 2022 at 7:44

Your Answer

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

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