{"id":21881738,"url":"https://github.com/r-barnes/barnes2019-compactness-flexibility","last_synced_at":"2026-02-28T19:01:47.638Z","repository":{"id":151219624,"uuid":"122377925","full_name":"r-barnes/Barnes2019-compactness-flexibility","owner":"r-barnes","description":"Reproduction materials for \"Gerrymandering and Compactness: Implementation Flexibility and Abuse\"","archived":false,"fork":false,"pushed_at":"2022-12-27T15:36:49.000Z","size":12840,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T19:33:40.453Z","etag":null,"topics":["compactness","gerrymandering","gis","political-science"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-barnes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-21T18:45:46.000Z","updated_at":"2023-10-18T22:09:45.000Z","dependencies_parsed_at":"2023-06-26T09:30:35.762Z","dependency_job_id":null,"html_url":"https://github.com/r-barnes/Barnes2019-compactness-flexibility","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/r-barnes/Barnes2019-compactness-flexibility","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-barnes%2FBarnes2019-compactness-flexibility","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-barnes%2FBarnes2019-compactness-flexibility/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-barnes%2FBarnes2019-compactness-flexibility/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-barnes%2FBarnes2019-compactness-flexibility/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-barnes","download_url":"https://codeload.github.com/r-barnes/Barnes2019-compactness-flexibility/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-barnes%2FBarnes2019-compactness-flexibility/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29948228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T18:42:55.706Z","status":"ssl_error","status_checked_at":"2026-02-28T18:42:48.811Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compactness","gerrymandering","gis","political-science"],"created_at":"2024-11-28T09:20:33.226Z","updated_at":"2026-02-28T19:01:47.609Z","avatar_url":"https://github.com/r-barnes.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"Software for \"Gerrymandering and Compactness: Implementation Flexibility and Abuse\"\n===================================================================================\n\n**Title of Manuscript**:\nGerrymandering and Compactness: Implementation Flexibility and Abuse\n\n**Authors**: Richard Barnes and Justin Solomon\n\n**Corresponding Author**: Richard Barnes (richard.barnes@berkeley.edu)\n\n**DOI Number of Manuscript**: TODO\n\n**Code Repositories**\n * [GitHub Repository](https://github.com/r-barnes/Barnes2019-compactness-flexibility)\n\nThis repository contains the code needed to produce the figures and data\ndescribed in the manuscript above.\n\n\n\nAbstract\n--------\n\nThe shape of an electoral district may suggest whether it was drawn with\npolitical motivations, or _gerrymandered_. For this reason, quantifying the\nshape of districts, in particular their compactness, is a key task in politics\nand civil rights. A growing body of literature suggests and analyzes compactness\nmeasures mathematically, but little consideration has been given to how these\nscores should be calculated in practice. Here, we consider the effects of a\nnumber of decisions that must be made in interpreting and implementing a set of\npopular compactness scores. We show that the choices made in quantifying\ncompactness may themselves become political tools, with seemingly innocuous\ndecisions leading to disparate scores. We show that when the full range of\nimplementation flexibility is used, it can be abused to make clearly\ngerrymandered districts appear quantitatively reasonable. This complicates using\ncompactness as a legislative or judicial standard to counteract unfair\nredistricting practices. This paper accompanies the release of packages in C++,\nPython, and R which correctly, efficiently, and reproducibly calculate a variety\nof compactness scores.\n\n\n\nTo Generate Figures\n-------------------\n\n### Install Dependencies\n\nFigures are known to generate correctly with Python (v3.6.8), R (v3.4.4), and pdfLaTeX (3.14159265-2.6-1.40.20, TeX Live 2019).\n\nInstall bash dependencies:\n\n    sudo apt install --no-install-recommends shapelib shapetools gdal-bin r-base make cmake python3 gcc g++ gfortran libudunits2-dev libgdal-dev libpython-dev\n\nSet up and activate environment:\n\n    conda env create -f environment.yml\n    conda env remove -n barnes2019_gerrymandering\n\nThe following R package versions were used to generate the figures in the paper.\n\n    corrplot     0.84\n    dplyr     0.8.0.1\n    GGally      1.4.0\n    ggplot2     3.1.0\n    ggrepel     0.8.1\n    gridExtra     2.3\n    reshape2    1.4.3\n    scales      1.0.0\n    sf          0.7-7\n    stringr     1.4.0\n    xtable      1.8-3\n\nThe following LaTeX packages were used to generate TeX figures in the paper:\n\n    graphicx (1.1a 2017-06-01)\n    siunitx (2.7s 2018-05-17)\n    tikz (3.1.4b 2019-08-03)\n\n\n\n### Via Github\n\nIn addition to the above, if you have obtained this code from Github, you must ensure you have acquired the code's submodules.\n\nClone the repo:\n\n    git clone https://github.com/gerrymandr/python-mander.git\n\nCheck out the submodules:\n\n    git submodule update --init --recursive\n\n### Build Figures\n\nFigures are known to generate without problems on a 2011 Thinkpad X201 with a Intel(R) Core(TM) i5 M480@2.67GHz CPU with 4 cores in 1 hour and 7 minutes using a peak of 700MB of RAM.\n\nAll of the figures are built by running a single command:\n\n    make\n\nMake will create a folder to run `cmake` in and then execute all the commands needed to generate the figures. The final figures will be saved to a folder named `figures/`. It may take quite a while.\n\n\n\nFile List\n------------------------\n\nThe repository contains the following files:\n\n * `data/cb_2015_us_cd114_20m.shp`: 20m resolution Congressional District boundaries from \"United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26.\"\n * `data/cb_2015_us_cd114_500k.shp`: 500k resolution Congressional District boundaries from \"United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26.\"\n * `data/cb_2015_us_cd114_5m.shp`: 5m resolution Congressional District boundaries from \"United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26.\"\n * `data/cb_2015_us_state_20m.shp`: 20m resolution state boundaries from \"United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26.\"\n * `data/cb_2015_us_state_500k.shp`: 500k resolution state boundaries from \"United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26.\"\n * `data/cb_2015_us_state_5m.shp`: 5m resolution state boundaries from \"United States Census Bureau. 2016. Cartographic Boundary Shapefiles. https://www.census.gov/geo/maps-data/data/cbf/cbf_cds.html accessed on 2017-08-26.\"\n * `figures/`: Directory containing generated figures\n * `output/`: Directory containing intermediate outputs\n * `submodules/`: Directory containing `compactnesslib` and `python-mander`, which are used to calculate the compactness scores themselves.\n * `tex/`: Directory containing TeX source for several of the figures.\n * `output/scores_double_vs_float`: Compactness scores as generated with single- versus double-precision floating-point. This file is presupplied because its effect size is small and generating it takes significant manual work. To generate it, replace `double` with `float` throughout `submodules/compactnesslib/api` and `submodules/compactnesslib/src` and rerun all score generation, per the makefile.\n * `output/effect_of_topography.tbl`: Compactness scores as calculated accounting for topography and not. This file is presupplied because its effect size is small and generating it takes significant manual work. To generate it, acquire NED 10m elevation data for the US (several gigabytes), cut the elevation data to the boundary of each congressional district using `gdal`, and then measure the length of the outline with and without topography using RichDEM.\n * `src/augmenter.cpp`: Adds scores to existing shapefiles.\n * `src/CMakeLists.txt`: Part of the build process.\n * `src/common.py`: Functions used my multiple of the scripts in `src/`.\n * `src/districtplot.py`: Plots district silhouettes.\n * `src/koch.cpp`: Generates a Koch snowflake.\n * `src/koch_scores.py`: Calculates scores for a Koch snowflake.\n * `src/make_figs.y`: Generates all of the intermediate figure images.\n * `src/res_bounded.py`: Calculates scores when superunit boundaries are accounted for.\n * `src/res_fig_gerrymandering.py`: Calculates joint effect of many other effects combined.\n * `src/res_projections.py`: Calculates effect of different projections on compactness scores.\n * `src/res_simp_indiv.py`: Calculates effect of simplifying district shapes when each district is considered independently.\n * `src/res_simp_together.py*`: Calculates effect of simplifying district shapes when groups of districts are considered as part of the simplification.\n * `src/Timer.cpp`: Used for timing various operations\n * `src/Timer.hpp`: Used for timing various operations\n\nBuild Issues\n============\n\n`error: can't combine user with prefix, exec_prefix/home, or install_(plat)base`\n\nIs a system configuration issue on your machine. Resolve it by editing `Makefile` from:\n```bash\ncd submodules/python-mander \u0026\u0026 python3 setup.py install --user\n```\nto\n```bash\ncd submodules/python-mander \u0026\u0026 python3 setup.py install --user --prefix=\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-barnes%2Fbarnes2019-compactness-flexibility","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-barnes%2Fbarnes2019-compactness-flexibility","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-barnes%2Fbarnes2019-compactness-flexibility/lists"}