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. Thanks in advance for help and thoughts.