Mapping Historic Census Data with QGIS

This tutorial is derived from Jamin Wells, “How to Map Historic Census Data with QGIS” and its modification by John Garrigus

Overview: This tutorial provides a basic introduction to mapping census data with QGIS.

Acquire and Manipulate Census Data:

  1. For this class, the instructor has downloaded a directory containing these files and shared it with you via OneDrive. Otherwise, you could download both a CSV file of census data and a corresponding shapefile from the NHGIS site, as described here: https://johngarrigus.com/gis/table-joins/
  2. To calculate change in racial demographics, open the CSV file in Excel and examine your data. Create a calculated column such as “Percent African American.” This is the column we will display on the map. Save as a CSV file.
  3. Extract the downloaded NHGIS files to a project folder. You should extract the main folder, the folders for the CSV and the Shapefile directories, and also the actual CSV file.

Import Shapefile and CSV to QGIS

  1. Open QGIS. Create a vector layer. Browse to the shapefile you downloaded. The CRS should be NAD83.
  2. Create a “delimited text file” layer (the comma button) and in the prompt box, choose the CSV file you downloaded from NHGIS and edited.
  3. File format = CSV; Geometry definition = No geometry (attribute only table); OK

Join the Shapefile to the CSV

  • Right click on the shapefile for your map in the layers panel. Click Properties. Click Joins.
  • Click the green plus sign.
    • Join layer = the CSV file you downloaded; Join field = GISJOIN; Target field = GISJOIN; OK
  • In the Properties box of the shapefile, click Symbology.
  • Try changing Single Symbol to Graduated. You will see only a few columns displayed as options for display. This is because CSV files do not store styling, just text. We need to get QGIS to recognize the calculated column as numbers (it sees it now as a string, not as an integer). You can use one of two methods to do this:
  • One method: Edit the Attribute Table to make the calculated column data appear as an integer. We can do this by making a duplicate column. To do this, right-click on the shapefile in the layers panel. Choose Open Attribute Table. Choose the abacus button to open the field calculator. Type in an “output field name;” this will be the header for your new column. Precision=4. Field type: Decimal number (real). Double-click on Fields and Values to expand the list. Find the column you wish to display on the map and double-click it to have it appear in the expression box. Click OK.
  • Other method: You can create a CSVT file to go along with your CSV file, indicating that QGIS should process that column as an integer. To do that, open the CSV file in Notepad or another text editor (not a word processor). Type a simple line reading “string”, “string”, (one for each text column) and “integer” (positioned for the column you wish to display). Save with same name as your CSV file, but as a .CSVT file. Save it to the same directory as the CSV file. This is a good time to start over with a new project file in QGIS, quickly reworking this tutorial, but importing your CSV file knowing it is now with its CSVT companion.

Display Data

  1. In the Properties box of the shapefile, click Symbology.
  2. Change Single Symbol to Graduated. Choose the column you wish to display. Click Classify. Apply. Try natural breaks. 10 categories. Choose a logical color ramp. OK.

Export your Map as a PDF for Saving or Submitting

  1. Choose Project–>new Print Layout
  2. Give it a title
  3. Click on Add Item–>Add Map, then draw a box in the main area. Map will appear.
  4. Click on Add Item–>Add Scale Ruler, then draw a box in the main area. Ruler will appear.
  5. Click on Add Item–>Add Label, then draw a text box for the title.
  6. Click on Add Item–>Add Legend; choose elements.
  7. Layout–>Export as PDF.