Skip to content

Instantly share code, notes, and snippets.

@BruOp
Last active February 1, 2020 01:37
Show Gist options
  • Save BruOp/cc47faea06cbeeeb628a6b9c69da1dcb to your computer and use it in GitHub Desktop.
Save BruOp/cc47faea06cbeeeb628a6b9c69da1dcb to your computer and use it in GitHub Desktop.
A Guide on Performing Spatial Joins with QGIS

A Guide to Spatial Joins in QGIS

In order to perform a spatial join for a set of points in QGIS, there are a few steps you may need to take care of before performing the join itself.

Download QGIS

Download QGIS

Create a New Project and Add Your Layers

Supported Data Formats

Get the points as a shapefile

If you're given a .CSV to represent your points data, the first thing you'll have to do is open the file in QGIS:

Tutorial for Importing CSVs

Next you'll probably want to save the layer as a shapefile in order to make changes to it (for some reason QGIS doesn't allow direct editing of CSV files)

Save CSV layer as Shapefile

Ensure All Your Layers are Using the Same Projection

You can double click on a layer in the bottom left to view its properties. Under general, you can see the projection format of the selected layer. If it is anything other than WGS84 then you'll need to follow the instructions below to reproject it:

Reproject a Layer

Perform the Spatial Join

Once you've done all this you should be able to perform the spatial join (finally!). To do so, follow this tutorial below:

Performing Spatial Joins

If the default tool is freezing or too slow, you could also try the MMQGIS plugin, which you can install from the Plugins menu at the top of the UI. It will appear as a seperate menu at the top once you've finished installing it.

Performing a Spatial Join with MMQGIS (scroll down)

Perform Additional Joins

If you need to perform a simple join based of column values, you can do so easily!

Performing Table Joins

Troubleshooting

Q: Something's not working! Why?!?

A: Check the projections of the layers you're trying to join. Make sure they are both the same.

Q: After reprojecting, my map moves to a completely different place!

A: You've probably changed the projection in the layer properties rather than saving a copy with the different projection. After you reproject, your new layer should lay right on top of the old one. If try to just change it in the properties, what QGIS will try to do is render the map as if the stored points (which could be in an arbitrary format) were latitude and longtitude coordinates. This is obviously wrong, don't do it.

Q: The layers in my project don't look right!

A: You've likely set the project projection to something other than WGS84. This is set by clicking the little button in the bottom right corner that probably says something like EPSG:4326 (OTF) (which is actually just the WGS84 projection). If it doesn't say that, click it and select EPSG:4326 / WGS84

Q: The layers don't look like the picture on the gov't website at all when I open them in my project

A: That's because most governments don't use WGS84 (which is a Mercator projection) for their own maps. Especially not Canada or New Zealand, as the Mercator projection introduces particularly extreme distortion for such places at extreme latitudes. There is no problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment