Not every dataset you want to use comes in spatial format. Often the data would come as a table or a spreadsheet and you would need to link it with your existing spatial data for use in your analysis. This operation is known as a Table Join and is done using the Join attributes by field value
Processing algorithm.
We will use a shapefile of census tracts for California and population data table from US Census Bureau to create a population map for california.
US Census Bureau provides TIGER/Line Shapefiles. You can visit the FTP site and download census tracts shapefile for California. Download Census Tracts for California file.
Americal FactFinder is a repository of all census data for the US. You can use Advanced Search and query for the Topic - Basic Count/Estimate and Geographies - All Census Tracts in California to create a custom CSV and download it. This tutorial uses TOTAL POPULATION | 2017 ACS 5-year estimates
data.
For convenience, you may directly download a copy of both the datasets from the links below:
Data Source [TIGER] [USCENSUS]
tl_2018_06_tract.zip
file in the QGIS Browser and expand it. Select the tl_2018_06_tract.shp
file and drag it to the canvas.tl_2018_06_tract
loaded in the Layers panel. This layer contains the boundaries of census tracts in California. Right-click on the tl_2018_06_tract
layer and select Open Attribute Table.GEOID
field is a unique identifier for each tract and can be used to link this layer with any other layer or table containing the same ID.ACS_17_5YR_B01003.zip
file and open the ACS_17_5YR_B01003_with_ann.csv
file in a text editor. You will notice that each row of the file contains information about a tract along with the unique identifier we saw in the previous step. Note that this field is called GEO.id2
in the CSV. You will also note that the HD01_VD01
column has population value for each of the census tract.ACS_17_5YR_B01003_with_ann
in the Layers panel. Now we are ready to create the table join. Go to .tl_2018_06_tract
as Input layer and GEOID
as the Table field. Select ACS_17_5YR_B01003_with_ann
as the Input layer 2 and GEO.id2
as the Table field 2. Leave other options to their default values and click the ... button to select the output file location and select Save to GeoPackage...
.joined.gpkg
and the output layer as joined
. Click Run.joined
loaded in the Layers panel. At this point, the fields from the CSV file are joined with the census tracts layer. You can close the Processing Toolbox for now. Right-click on the joined
layer and select Open Attribute Table.HD01_VD01
field containing population estimates.joined
layer and click the Open the Layer Styling Panel button.Graduated
from the drop-down menu. As we are looking to create a population map, we want to assign different color to each census tract feature based on the population estimate. Select HD01_VD01
as the Column. Select a color ramp of your liking from the Color ramp drop-down. In the Mode, select Quantile (Equal Count) with 5
Classes. Click the Classify button and see the map layer update with a color assigned to a population range. You can close the Layer Styling panel once you are satisfied with the map.HD01_VD01
field to count the total population of the state. Enter the query in the Query tab and click Execute. The result will appear in the bottom panel. You can verify that the result matches the population of California.select sum(HD01_VD01) as population from joined
group by
clause to group all census tracts by county and create a table of total population by county. The query also sorts the result by population. We can also cross-verify that the county with FIPS id 037
(Los Angeles County) is the most populated county in california .select COUNTYFP as county, sum(HD01_VD01) as population from joined group by COUNTYFP order by population desc
This work is licensed under a Creative Commons Attribution 4.0 International License