Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
podcast
Filter by Categories
ArcGIS Pro
GDAL
GeoJson
Map
Python
QGIS
Uncategorized

Spatial Joins in QGIS

Unraveling the Power of Spatial Joins in QGIS: A Comprehensive Guide

Spatial joins are an invaluable tool for anyone working with geographic data, and in this blog post, we’ll explore their capabilities in QGIS – one of the most popular open-source GIS software.

Our discussion will guide you through the fundamentals of spatial joins, their various applications, and the key considerations to ensure accurate and efficient processing. We’ll delve into the types of spatial relationships used in QGIS, such as intersect, overlap, contain, are within, equal, cross, and touch, and examine their implications for your analysis.

Additionally, we’ll provide step-by-step guides to using different spatial join tools in QGIS, including “Join attributes by nearest”, “Join attributes by location (summary)”, and “Join attributes by location”. By the end of this blog post, you’ll have a solid understanding of when to use spatial joins, how to perform them in QGIS, and the potential insights they can unlock for your projects.

Want to stay ahead of the geospatial curve? Listen to our podcast!

Step-by-step guide to using the Join attributes by the nearest tool in QGIS

The “Join attributes by nearest” tool in QGIS allows you to join attributes from one layer to another based on the nearest features. Here’s a step-by-step guide to using this tool:

  1. Load the spatial layers: Click on “Layer” in the menu bar and select “Add Layer” to add the two spatial layers you want to join. For example, you might have a point layer representing schools and another point layer representing hospitals.
  2. Check the Coordinate Reference System (CRS): Ensure that both layers have the same CRS. To check or modify the CRS, right-click on each layer in the “Layers” panel, select “Properties”, and then click on the “Source” tab. If the CRS is different, you can reproject one of the layers by right-clicking on it, selecting “Export”, and then “Save Features As…”. Choose a suitable CRS in the “Coordinate Reference System” section and save the new layer.
  3. Open the “Join attributes by nearest” tool: Go to “Processing” in the menu bar, then “Toolbox”. In the “Processing Toolbox” panel, search for “Join attributes by nearest” and select the tool.
  4. Configure the join parameters:
    • For “Input layer”, choose the layer you want to enrich with attributes from the other layer (e.g., the schools point layer).
    • For “Join layer”, select the layer containing the attributes you want to join (e.g., the hospitals point layer).
    • Specify the maximum number of nearest features you want to join. By default, it’s set to 1, which means the tool will only join the attributes of the nearest feature.
    • Set a maximum search distance to limit the join to features within a certain distance.
    • Under “Joined fields”, you can select specific fields to join or leave it as the default setting to join all fields.
    • You can choose a prefix to add to the joined field names.
  5. Run the join: Click “Run” to perform the join. The resulting layer will be added to the “Layers” panel.
  6. Save the output layer: To save the output layer, right-click on it in the “Layers” panel, select “Export”, and then “Save Features As…”. Choose the desired file format (e.g., Shapefile or GeoJSON) and specify the output location.

You have now successfully performed a “Join attributes by nearest” operation in QGIS.

Step-by-step guide to using the Join attributes by location (summary) tool in QGIS

The “Join attributes by location (summary)” tool in QGIS allows you to perform spatial joins while calculating summary statistics for the attributes in the join layer. Here’s a step-by-step guide to using this tool:

  1. Load the spatial layers: Click on “Layer” in the menu bar and select “Add Layer” to add the two spatial layers you want to join. For example, you might have a polygon layer representing districts and a point layer representing schools.
  2. Check the Coordinate Reference System (CRS): Ensure that both layers have the same CRS. To check or modify the CRS, right-click on each layer in the “Layers” panel, select “Properties”, and then click on the “Source” tab. If the CRS is different, you can reproject one of the layers by right-clicking on it, selecting “Export”, and then “Save Features As…”. Choose a suitable CRS in the “Coordinate Reference System” section and save the new layer.
  3. Open the “Join attributes by location (summary)” tool: Go to “Processing” in the menu bar, then “Toolbox”. In the “Processing Toolbox” panel, search for “Join attributes by location (summary)” and select the tool.
  4. Configure the join parameters:
    • For “Base layer”, choose the layer you want to enrich with summary statistics from the other layer (e.g., the districts polygon layer).
    • For “Join layer”, select the layer containing the attributes you want to use for summary calculations (e.g., the schools point layer).
    • Choose the type of spatial relationship you want to use for the join. For example, you can choose “within” to join attributes of the polygon that contains each point.
    • In the “Fields to summarize” section, select the fields from the join layer that you want to use for calculating summary statistics. You can use the “Summarize only selected fields” option to specify particular fields, or join all fields by default.
    • Choose the summary statistics you want to calculate for the selected fields. Some options include count, sum, mean, median, minimum, maximum, and standard deviation. Multiple statistics can be calculated for each field.
    • Optionally, you can choose a prefix to add to the output field names.
  5. Run the join: Click “Run” to perform the join. The resulting layer will be added to the “Layers” panel.
  6. Save the output layer: To save the output layer, right-click on it in the “Layers” panel, select “Export”, and then “Save Features As…”. Choose the desired file format (e.g., Shapefile or GeoJSON) and specify the output location.

You have now successfully performed a “Join attributes by location (summary)” operation in QGIS. This tool is useful for aggregating and summarizing attribute data based on spatial relationships.

Step-by-step guide to using the Join attributes by location tool in QGIS

The “Join attributes by location” tool in QGIS allows you to perform a spatial join, combining attributes from one layer to another based on their spatial relationship. Here’s a step-by-step guide to using this tool:

  1. Load the spatial layers: Click on “Layer” in the menu bar and select “Add Layer” to add the two spatial layers you want to join. For example, you might have a point layer representing cities and a polygon layer representing administrative boundaries.
  2. Check the Coordinate Reference System (CRS): Ensure that both layers have the same CRS. To check or modify the CRS, right-click on each layer in the “Layers” panel, select “Properties”, and then click on the “Source” tab. If the CRS is different, you can reproject one of the layers by right-clicking on it, selecting “Export”, and then “Save Features As…”. Choose a suitable CRS in the “Coordinate Reference System” section and save the new layer.
  3. Open the “Join attributes by location” tool: Go to “Processing” in the menu bar, then “Toolbox”. In the “Processing Toolbox” panel, search for “Join attributes by location” and select the tool.
  4. Configure the join parameters:
    • For “Input layer”, choose the layer you want to enrich with attributes from the other layer (e.g., the cities point layer).
    • For “Join layer”, select the layer containing the attributes you want to join (e.g., the administrative boundaries polygon layer).
    • Choose the type of spatial relationship you want to use for the join. For example, you can choose “within” to join attributes of the polygon that contains each point.
    • Under “Joined fields”, you can select specific fields to join or leave it as the default setting to join all fields.
    • Optionally, you can choose a prefix to add to the joined field names.
  5. Run the join: Click “Run” to perform the join. The resulting layer will be added to the “Layers” panel.
  6. Save the output layer: To save the output layer, right-click on it in the “Layers” panel, select “Export”, and then “Save Features As…”. Choose the desired file format (e.g., Shapefile or GeoJSON) and specify the output location.

You have now successfully performed a “Join attributes by location” operation in QGIS. This tool is useful for combining datasets based on their spatial relationships, such as finding which administrative boundary a city belongs to.

Here is a table describing the different spatial relationships used in QGIS:

Spatial RelationshipDescription
IntersectTwo features are considered to intersect if their geometries share at least one point in common. This relationship includes cases where one feature is entirely contained within another, as well as cases where features partially overlap.
OverlapTwo features overlap when their geometries share some area but not all, and neither feature is completely within the other. In other words, their intersection results in a geometry with a non-zero area, and neither feature completely contains the other.
ContainA feature is considered to contain another feature if its geometry completely encloses the other feature without any shared boundary points. In the case of polygons, it means that one polygon completely contains the other, including its interior and boundary.
Are withinThis is the inverse of the “contain” relationship. A feature is within another feature if its entire geometry is enclosed by the other feature without any shared boundary points.
EqualTwo features are equal if their geometries are identical in shape, size, and location. This relationship can be applied to any geometry type, including points, lines, and polygons.
CrossTwo features are considered to cross if their intersection results in a geometry of a lower dimension. For example, a line crosses a polygon if it enters and exits the polygon, or two lines cross if they intersect at a single point but don’t share any line segments.
TouchTwo features are considered to touch if their geometries share at least one common boundary point, but their interiors don’t intersect. This relationship applies to polygons that share an edge or a single point, and to lines or points that intersect at their endpoints.
These spatial relationships form the basis for various geospatial operations and analyses in QGIS, including spatial joins, selections, and queries.

Things to be aware of when using spatial joins in QGIS

When using spatial joins in QGIS, there are several factors to consider to ensure accurate and efficient processing. These include:

  1. Coordinate Reference System (CRS): Make sure that both layers use the same CRS or are reprojected to a common CRS. If the layers have different CRSs, spatial relationships may be distorted, leading to incorrect join results.
  2. Spatial relationships: Choose the appropriate spatial relationship for your analysis (e.g., intersect, within, contains, nearest, buffer). Ensure you understand the implications of each spatial relationship type to avoid misinterpretation of the results.
  3. Join field selection: Be selective when choosing fields to join. Joining unnecessary fields can lead to larger file sizes and slower processing times. In the “Join Attributes by Location” tool, you can select specific fields to join, rather than joining all fields by default.
  4. Layer size and complexity: Large or complex layers may lead to longer processing times and high memory usage. If possible, simplify the geometries or filter out unnecessary features before performing a spatial join.
  5. Topological errors: Incorrectly digitized features or topological errors (e.g., gaps, overlaps) in the input layers can cause issues when performing spatial joins. It’s important to validate and correct any errors before joining the datasets.
  6. Attribute data types and field names: Be aware of the data types and field names of the attributes you’re joining. In some cases, you may need to modify the field names or data types to ensure compatibility.
  7. Output format: Choose an appropriate output format for your needs, such as Shapefile, GeoJSON, or geopackage. Different formats have varying capabilities and limitations, so make sure the selected format supports the required features and attributes.
  8. Data privacy and licensing: When working with multiple spatial datasets, be aware of any data privacy concerns or licensing restrictions. Combining datasets may inadvertently disclose sensitive information or violate data usage agreements.

By considering these factors when using spatial joins in QGIS, you can ensure accurate results and efficient processing.

About the Author
I'm Daniel O'Donohue, the voice and creator behind The MapScaping Podcast ( A podcast for the geospatial community ). With a professional background as a geospatial specialist, I've spent years harnessing the power of spatial to unravel the complexities of our world, one layer at a time.

Leave a Reply