Wednesday, 2 May 2018

How to add CSV data with no coordinates to a polygon layer in QGIS?


I would like to add attributes from an spss database (around 300 cases) to a polygon layer in QGIS. Both datasets have a column with unique IDs. I exported the spss data to a CSV file which does not contain x,y values.


The "add delimited text layer" plugin seems to require x and y values. How can I add the CSV data to the polygons?



Answer



You need to Join the attribute table and the CSV. Assuming the Unique IDs are common between the spatial data and the CSV, they will be used as the join field. See this tutorial for great step-by-step instructions.


This is a summary of the points from the tutorial. See the tutorial for more details and screenshots.



  1. add the spatial data to the view in QGIS


  2. open the CSV in a text editor

    • make sure any column names that are only numbers are enclosed in double quotes (e.g. a column named 2009 should be changed to "2009")

    • if any of the data is numeric you will need to create a CSVT file so that QGIS doesn't convert the field to text (if you want to perform math with those numbers)



  3. examine the attribute table and the CSV to know which column names will be used for the join

    • probably the Unique IDs for the data in Martin's question




  4. add the CSV file to QGIS by clicking (on the menu) Layer > Add Vector Layer

    • the table should appear in the Table of Contents



  5. make sure the data in the CSV table was imported correctly by right-clicking on it (in the Table of Contents) and choosing Open Attribute Table

  6. double-click on the spatial data layer to open Properties

  7. click the Joins tab

  8. click the + icon to create a new join


    • Join Layer is the CSV table

    • Join Field is the join column from the CSV table (identified in step 3)

    • Target Field is the join column from the spatial layer (identified in step 3)

    • click OK



  9. open the attribute table for the spatial layer to see the joined data

  10. note that joins are temporary


    • save the spatial data as a new layer if you want to make the join permanent




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...