Code Monkey home page Code Monkey logo

qgis3redistricter's Introduction

qgis3redistricter

Redistricting plugin for QGIS v3. This now exists as part of the QGIS repository and can be downloaded through the QGIS Plugins library.

This plugin takes a vector layer and allows you to graphically update a "district" column, and instantly see how many people live within that district.

Full install and instructions for use are available at https://www.qgisredistricting.com

Quick setup

You will need to provide a vector layer with a population column. Create a new project and add your vector layer to the project.

Download and install this plugin, preferably directly through the QGIS plugin library.

Start the plugin by clicking "Plan Manager" and then select "Create New Plan." A list of parameters will come up, including plan name, layer name, number of target districts, population field, population tolerance, district field, and any data fields, discussed in detail below.

Plan name: The name of your redistricting plan. Choose carefully as old plans may be overwritten if you have a plan with the same name. Layer to district: Your target vector layer that you've loaded above Number of districts: The target number of districts you want to create - for instance, if you are reapportioning the Victorian Legislative Assembly, which has 88 seats, this number would be 88. Population field: The attribute column on the layer which contains the number of people represented by each polygon. (If you don't know what this is, right-click your layer and look at your vector's attribute fields. Depending on your data source, you may not have a population field, in which case you can't really redistrict with that layer.) Equal population tolerance: Many states have an equal population threshold, where districts can have plus or minus x% of people and still be considered "equal population." Enter that number here. For maps for the United States Congress, which has a 0% variance, or to make your map where districts must be equal, leave at 0%. Optional second population field: Works exactly the same way as the population field, designed for countries which use multiple population fields for reapportionment. If you do not need this, you may be able to use this field creatively in order to add a constraint to your map. District field: The column with the district name or number. If you are creating a new plan, you may not have this column on your map, since you have to create it yourself. If that's the case, select "Create New Field" and the plugin will attempt to add a new field to your layer. Data field: You can add any number of data fields to your redistricting plan, depending on what data exists on your layer's attribute table. These fields will update with the map to let you know real time statistics about your map. For instance, if you have a column on your layer with a secondary population count, such as number of non-native English speakers in the polygon, you can easily sum that information using the data field. Click on the "+" to add a field to the list.

You can automatically colour your map using the "Create map styles from districts" button.

Once you have set up your plan, all you have to do to update your plan is to select polygons on the map using the built in QGIS select tool, select the active district using the active district slider, and then click "Update Selected Polygons." Larger selections may take a few seconds to update.

One of the more valuable advanced tools worth mentioning is the geographic selection field tool. However, in order for this to work, the geography must be on the attribute table for your current redistricting layer. This may require advanced procedures such as joining other boundary files if your data set does not have this on the file.

qgis3redistricter's People

Contributors

couteau avatar johnpholden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

qgis3redistricter's Issues

Plans not saved with PostgreSQL data source

When using a shapefile for redistricting, the plans appear to be saved in a file named:
_Redistricting Plan.qgis.red in the same directory as the shapefile.
But using a PostgreSQL as the data source the plans are not saved. Am I missing something?

Python error on launch

I get the following error when intitating Redistricter after installing it with QGIS 3.24 Tisler; the plugin launches, I go to create a new redistricting plan, click on OK and this pops up, the plugin will not create a new plan and will not proceed.

TypeError: int() argument must be a string, a bytes-like object or a number, not 'QVariant'
Traceback (most recent call last):
File "C:\Users/bjwig/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis3redistricter-master\StattoRedistrict.py", line 2282, in updatePanelAndSaveParameters
self.saveParameters()
File "C:\Users/bjwig/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis3redistricter-master\StattoRedistrict.py", line 1307, in saveParameters
self.totalpop = self.totalpop + int(feature[self.popfield])

Python error when creating plan

Hi
When I go to create a plan, I get a python error of:
self.totalpop = self.totalpop + int(feature[self.popfield])
TypeError: int() argument must be a string, a bytes-like object or a number, not 'QVariant'

I'm using StatsCan boundary and census data.

Python error launching plugin

After installing the plugin in QGIs and creaing a new redistricting plan, I click on OK and get the following error; the plugin launches but does not proceed and will not work:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'QVariant'
Traceback (most recent call last):
File "C:\Users/bjwig/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis3redistricter-master\StattoRedistrict.py", line 2282, in updatePanelAndSaveParameters
self.saveParameters()
File "C:\Users/bjwig/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis3redistricter-master\StattoRedistrict.py", line 1307, in saveParameters
self.totalpop = self.totalpop + int(feature[self.popfield])

Experimental branch won't load

Not sure if you want issue reports on experimental branch, but I saw John speak at QGIS NA 2020 and he recommended using experimental because of a recently fixed memory leak. Unfortunately, I can't get it to load. I have downloaded master and installed and loaded successfully.

Error in experimental comes when trying to initialize the plugin from the toolbar button or Plugins menu item. A dialog box appears with:

Attribute Error:

'StattoRedistrictDockWidget' object has no attribute 'btnCurrentPlan'

run[StattoRedistrict.py:430]

The error line is:

            self.dockwidget.btnCurrentPlan.clicked.connect(self.loadActivePlanParametersDialog)

Platform info:

QGIS version 3.14.1-Pi QGIS code revision de08d6b71d
Compiled against Qt 5.9.5 Running against Qt 5.9.5
Compiled against GDAL/OGR 3.0.4 Running against GDAL/OGR 3.0.4
Compiled against GEOS 3.8.0-CAPI-1.13.1 Running against GEOS 3.8.0-CAPI-1.13.1
Compiled against SQLite 3.22.0 Running against SQLite 3.22.0
PostgreSQL Client Version 10.12 (Ubuntu 10.12-0ubuntu0.18.04.1) SpatiaLite Version 4.3.0a
QWT Version 6.1.3 QScintilla2 Version 2.10.2
Compiled against PROJ 7.0.0 Running against PROJ Rel. 7.0.0, March 1st, 2020
OS Version Linux Mint 19.1
Active python plugins GeoCoding; tiss; DotMap; quick_map_services; qgis3redistricter-master; QuickWKT; Socrata; BivariateLegend; postgisQueryBuilder; mmqgis; firstaid; MetaSearch; db_manager; processing

Plugin won't read "int" type

I am trying to make a map using a shapefile and population data in an XLSX file. The first time I used the plugin using this data set worked fine, but I have now been receiving this error after restarting QGIS.

Here is the issue I am having:

  1. Load shapefile
  2. Load XLSX with population field
  3. Join shapefile and XLSX
  4. Load plugin
  5. Make plan and select appropriate fields
  6. "TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'"

QGIS reads the population field as an "int" type. The district and data fields are "QString" types. Is this an issue with the plugin or the data set?

Can't load plugin

I'm a long-time ArcGIS user, but somewhat new to QGIS, so it's somewhat likely that I'm doing something wrong here.
I've downloaded qgis3redistricter-1.0-beta.zip.
Select Install from ZIP from the Manage and Install Plugins menu.
The following error message is generated when I install:
image
However, Statto Redistricter QGISv3 is listed as installed after the error window is closed.
When I click on the plugin, the same error message appears.
I'm running QGIS 3.14 now, results were the same in v3.12

Plan Attributes Table displays incorrect information

Problem: When reloading a previously created Plan, the Redistricting Attributes Panel does not display correct information. I created a Plan with 5 districts. After reopening the Plan the Attributes Panel displays the following rows: Unassigned, NULL, 1, 2, 3, 4.

Steps: Create new basic plan with 5 districts -- no extra options. Assign some polygons to District 1. Save the QGIS project. Close QGIS. Reopen QGIS. Reload the Redistricting Plan previously created. (Same problem results when you keep QGIS open and just close the Redistricting Plugin Main Panel, and then restart the Redistricting Plugin and reopen the Plan.)

Shapes and data file: ct_bg_proj_P2_2020tiger.zip. Download URL: https://redistrictingdatahub.org/dataset/20212030-ct-hastaqdna-population-projections-joined-to-2020-census-block-groups-p2/

Configuration: Windows 10 with most recent updates. QGIS version 3.20.0-Odense (downloaded on 6/30/2021). Plugin: Statto Redistricter QGISv3, Installed Version: 2.1.3. (I had the same problem with the plugin in QGIS 3.16, before installing QGIS 3.20.)

See also attached PDF, with screen shots.

Problem After Closing Redistricting Plugin 06-30.pdf

'Update selected polygons' has no visible effect

Thank you for the plugin!

After some difficulties creating a new plan (Python errors on creation and loading of plans -- when I started fresh with a clean new layer, in order to file an issue, I could not reproduce them), I am now having difficulties assigning precincts to districts.

It is possible (or likely) that I have just done something unexpected and wrong.

For work on a municipal redistricting, I have taken the precinct shapefile from the Secretary of State, done a Feature Filter query to restrict it to the relevant county, exported the features to KML, and manually deleted precincts from the KML which lie outside the city limits. (I work with XML and KML regularly, and am confident I did not accidentally corrupt the KML data.) In the plugin, I have created a new plan with 9 districts, adding a new attribute for the district data. The plugin pane shows 600,000 voters (give or take) in District 0 Unassigned, an 800% deviation, and 0 voters in each of districts 1-9, a 100% deviation. It all looks plausible and correct.

My first exercise will be reproducing the existing districts, so I have a layer imported from elsewhere, showing the existing district boundaries, and I set the redistricting layer to 30% opacity so the status quo districts shine through and I can assign precincts to districts. Selecting a precinct works fine. Either before or after selecting one or more precincts, I can set the Active District to the correct value. Then I click 'Update selected polygons', and the selection is cleared. No change to the display of the precinct, no change to the population totals or deviations of the district I'm trying to assign them to or to Unassigned.
Since QGIS is displaying log messages, I can see that when I click 'Update selected polygons', a log message beginning with a time stamp and continuing WARNING {'': , '1': , '2': , '3': , '4': , '5': , '6': , '7': , '8': , '9': } is added to the General log window. Nothing in the Python warning window.

Seeing from comments in issue 7 that testing may be better with some formats or others, I guess my next step is to see if I can convert the KML to a shapefile and reproduce the problem.

Error Creating Plan

I used this tool right after seeing the youtube video. I kicked the tires for a couple of hours and it worked great. I need to demo this to others in my local government next Tuesday, and am starting to run into issues. I receive the following error when trying to create a plan. BTW, this is a great tool. Thank you for creating it.

An error has occurred while executing Python code:

KeyError: 'None'
Traceback (most recent call last):
File "C:/Users/rslivinsky/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis3redistricter-master\StattoRedistrict.py", line 2084, in updatePanelAndSaveParameters
self.saveParameters()
File "C:/Users/rslivinsky/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis3redistricter-master\StattoRedistrict.py", line 1153, in saveParameters
self.totalpop2 = self.totalpop2 + int(feature[self.popfield2])
KeyError: 'None'

Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
QGIS version: 3.14.0-Pi Pi, 9f7028fd23

Python Path:
C:/PROGRA1/QGIS31.14/apps/qgis/./python
C:/Users/rslivinsky/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/rslivinsky/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA1/QGIS31.14/apps/qgis/./python/plugins
C:\PROGRA1\QGIS31.14\apps\Python37
C:\PROGRA1\QGIS31.14\apps\Python37\Scripts
C:\Program Files\QGIS 3.14\bin\python37.zip
C:\PROGRA1\QGIS31.14\apps\Python37\DLLs
C:\PROGRA1\QGIS31.14\apps\Python37\lib
C:\Program Files\QGIS 3.14\bin
C:\PROGRA1\QGIS31.14\apps\Python37\lib\site-packages
C:\PROGRA1\QGIS31.14\apps\Python37\lib\site-packages\win32
C:\PROGRA1\QGIS31.14\apps\Python37\lib\site-packages\win32\lib
C:\PROGRA1\QGIS31.14\apps\Python37\lib\site-packages\Pythonwin
C:/Users/rslivinsky/AppData/Roaming/QGIS/QGIS3\profiles\default/python

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.