Just found this on the Harvard website (Harvard University QGIS Workshop) and it is something I have always done in ArcGIS, never thinking that it was even possible in QGIS, afterall why would I when ArcGIS has a big shiny “Spatial Join” button. So I was pretty surprised to read this, and then ticked another box off the list of QGIS v ArcGIS…I tell you now, the list is running pretty equal at present, the only thing missing is a 3D element to QGIS…..
Source: Harvard University QGIS Workshop 26/07/2013
A common GIS task is to join the attributes from one spatial data layer to another. In this example we will join the attribute table from a polygon layer to a points layer, based on which polygon contains the points.
- For this exercise, we’ll use a set of points generated in Google Maps, showing some interesting sites in Taiwan
- Add Vector Data, set UTF-8 encoding, and browse to china/taiwan_points.kml
- Save As filename “TW_pts_big5” as format = ESRI Shapefile and encoding = BIG5 (we want to join BIG5 attribute table to this target layer, so SET CORRECT ENCODING FOR THE DATA THAT WILL BE JOINED)
- Add the newly created TW_pts_big5 layer and remove the imported taiwan_points KML import layer.
- Target Points layer should be ready for the join
- Now we want to Add Vector Layer and browse to the TW_POP layer, encoding = big5
- Open the Attribute Table to make sure the encoding looks okay. If it looks fine, close the attribute table.
- Go to menu VECTOR | DATA MANAGEMENT TOOLS | JOIN ATTRIBUTES BY LOCATION
- Set the TARGET LAYER = TW_points_big5, set the JOIN LAYER = TW_POP
- Click on the OUTPUT SHAPEFILE BROWSE button to set output path, filename, and encoding = big5, then click SAVE
- Click OK and you will be prompted to add the new join shapefile to the TOC (table of contents), click YES
- Open the Attribute Table of the new join layer. Each point feature now includes the attributes from the JOIN layer, having done a SPATIAL JOIN on the polygon that the point was located in.