Skip to content

Updating the Congressional District Map Using a Geodatabase or Individual State Shape Files

tmpayton edited this page Dec 12, 2023 · 1 revision

Method 1: Merge State Shape files

Prerequisites: geopandas pip install geopandas

  1. Checkout this branch
  2. Ensure that SOURCE_FILE is set to districts.shp and replace all instances of GEOID with GEOID20
  3. In terminal, go to data folder in fec-cms project cd fec-cms/fec/fec/static/js/data
  4. python3 merge_shape_files.py
  5. Go back to root of project
  6. npm run build-js
  7. cd fec/
  8. ./manage.py runserver (might need to clear cookies in browser)

Note: I got a scraping ssl error at first, the fix can be found here Scraping: SSL: CERTIFICATE_VERIFY_FAILED

Method 2: Use QGIS to extract shape files from geodatabase

Prerequisites: QGIS software (this may take awhile).

  1. Download geodatabase from the Census website
  2. Open QGIS Layer > Add Layer > Add Vector Layer (make sure directory is highlighted) image
  3. Find the layer that says Current_Congressional_DIstricts in the Layer pane image
  4. Right click on layer > Save features as > ESRI shape file
  • save in ~/fec-cms/fec/fec/static/js/data/src directory and name it “districts” image
  1. In terminal, go to data folder in fec-cms project cd fec-cms/fec/fec/static/js/data
  2. ./create_districts_topo.sh
  3. Go back to root of project
  4. npm run build-js
  5. cd fec/
  6. ./manage.py runserver (might need to clear cookies in browser)

Method 3: Use GDAL to convert geodatabase to shape file

  1. brew install gdal (this will take awhile)
  2. Download geodatabase from the Census website
  3. ogr2ogr -f "ESRI Shapefile" "{folder to put shp files}" "{name of geodatabase}.gdb" This will generate a folder with shape files.
  4. Move all "current_congressional_districts" files to ~/fec-cms/fec/fec/static/js/data/src. There should be a .prj file, .dbf file, .shx file, and .shp file
  5. In terminal, go to data folder in fec-cms project cd fec-cms/fec/fec/static/js/data
  6. Open file create_districts_topo.sh
  • ensure that the variable SOURCE_FILE is set to the name of your shape file from step 4.
  • ensure that on line 19 & 21 d.properties.GEOID says GEOID and not GEOID20
  1. ./create_districts_topo.sh
  2. Go back to root of project
  3. npm run build-js
  4. cd fec/
  5. ./manage.py runserver (might need to clear cookies in browser)

Note: The GEOID property is different in the national shape files(GEOID) vs the individual state shapefiles (GEOID20). Depending on which method is used this needs to be changed in the ./create_districts_topo.sh script.