Perform a Table Join in QGIS
Need help turning your spreadsheet data into a map? In this tutorial, you will learn how to join tables to GIS shapefiles to create a new, mappable dataset with both geographic boundaries and statistical or attribute information.
1. Understanding Table Joins: Why Connect Data to Geography?
Often, spreadsheets contain useful information we want to map. GIS software, however, does not know how to translate a spreadsheet without any inherent spatial information (such as point coordinates) into a visual map.
Consider a spreadsheet containing demographic statistics for various towns. While this data is clearly geographic – arranged by town– if we were to bring it into a GIS program, the program would not know (without being told by you) which column to interpret as the “geography” to display visually. Formats like .csv or .xlsx are not inherently spatial data formats.
On the other hand, a dataset of town boundaries, often available as a shapefile, is an inherently geospatial format. Because this data is spatial, GIS software can recognize it and automatically make a map out of it.
GIS software displays spatial data, but how is that data organized behind the scenes? It's stored in what's called an attribute table, which functions much like a spreadsheet or a database table.
- Each row in the table represents a distinct geographic feature on your map (for example, one town polygon).
- Each column in the table holds a specific piece of information, or attribute, about that feature (such as the town's name, its unique ID, or its population count).
While this table provides fundamental information and links to the map's shapes, it often doesn't contain all the statistical data you might want to map. That's why connecting it with other spreadsheets is essential for showing meaningful statistics.
Need help understanding the best way to structure your data for mapping, or if a join is the right approach for your project? Schedule a consultation with our team.
2. How Table Joins Work: The Core Mechanics
To perform a join, you must have a column in each dataset which contains the same literal values. Factors such as case sensitivity and hidden characters matter significantly. The values must be exactly the same in both tables for the join to work.
For instance, if you're joining a spreadsheet of demographic data to a spatial layer of geographic units, you would use a common column found in both datasets, such as a unique geographic identifier (e.g., a FIPS code or a town name). Column headers do not necessarily have to match, but the values inside the columns’ cells must be identical.
For a successful join, both the spatial and non-spatial datasets must contain a unique identifier column with exact matching values. Common join keys include unique IDs, shared names, or other distinct alphanumeric codes. Pay close attention to case sensitivity and leading/trailing spaces.
If your data requires cleaning or a join key isn't immediately obvious, our team can help strategize the best approach. Consult with us for assistance in preparing your data for a robust join.
3. Step-by-Step in QGIS: Connecting Tabular Data to Spatial Layers
This section demonstrates the table joining process in QGIS using a common scenario: connecting your prepared tabular data (a spreadsheet) to a corresponding GIS spatial layer (a shapefile).
Join steps:
- Add your spatial layer (e.g., a polygon shapefile of geographic units) to the QGIS document.
- Add your statistical tabular data (CSV or XLSX) to the map.
- Right-click your spatial layer in the layer list and select Properties.
- In the menu, select Joins.
- In the bottom of the wizard interface, select the Add new join button.
- Configure the join parameters:
- Join layer: Select your tabular data layer.
- Join field: Select the column in your tabular data that contains the common identifier.
- Target field: Select the column in your spatial layer's attribute table that contains the matching common identifier.
- Select the checkbox next to Joined Fields. You can selectively choose which fields from your tabular data you wish to add to the spatial layer's attribute table.
- Select OK.
- Select Apply.
- Select OK.
- Right-click your spatial layer in the layer list and select Open Attribute Table.
- Confirm the join worked by checking that the new fields from your tabular data are populated.
- Important! Joins performed within the QGIS document are ephemeral and will not save with the project file unless exported. To preserve the joined data, right-click the joined spatial layer, select Export → Save Features As and save it as a new geospatial dataset (e.g., a new shapefile or GeoPackage).
4. Applying Joins to Your Own Data: General Principles & Troubleshooting
The principles demonstrated in the step-by-step example can be applied to join any tabular data to a GIS shapefile. The key is to identify a reliable common identifier between your datasets and ensure its consistency.
- Identify your unique join key.
- Check for exact matches, including case and hidden characters.
- Ensure data types are compatible (e.g., numbers vs. text for join fields).
- Consider one-to-many relationships and how they will join (QGIS only takes the first match).
Table joins can be deceptively complex, especially with real-world data. If you encounter issues with unmatched records, unclear join keys, or data inconsistencies, our team is here to help you troubleshoot and refine your join strategy. Schedule a consultation to ensure your data is accurately mapped.