Joining Data in QGIS

Getting Started

Note: This tutorial uses data downloaded from Los Angeles Open Data portal (see: Quick Visual Guide to Visualizing Data on LA Open Data Portal)

Download QGIS if you do not have it installed: http://www.qgis.org/en/site/forusers/download.html ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Next download the following datasets:

http://boundaries.latimes.com/1.0/boundary-set/la-county-neighborhoods-v5/?format=shphttp://sandbox.idre.ucla.edu/mapshare/data/usa/census/Los_Angeles_ZipCodes.zip

Most GIS files (also called shapefiles) will be in a zipped format, so be sure to unzip them!

Mac Example:https://asmand.files.wordpress.com/2015/09/unzip-mac.gif

PC Example:https://www.youtube.com/watch?v=ZQOYqzGHiDY

How to add vector data

  1. Click the weird V to the left of the main menu
    qg_image0
  2. Click Browse
    qg_image1
  3. Find the “l.a county neighborhood (v5).shp” file and click “Open”
    qg_image2
  4. Now select open
    qg_image3
  5. Now the vector file should show up in the window:
    qg_image4

Working with layers:

  1. Let’s add another GIS file called Los_Angeles_ZipCodes

    qg_image5

  2. Notice what happens right after you add it:

    qg_image6

  3. It appears on top of the La county neighborhood (v5) layer which masks it from view.

  4. If you hit the box with the X you can toggle it on and off.

    qg_image7

  5. You can also drag the layer up and down.

    qg_image8

  6. You can right click or cmd + click on the layer to do various things, such as open an attribute table, remove the layer, or copy it.

    qg_image9

  7. Let’s click on “Open Attribute Table”:

qg_image10

  1. Here you can see all the data that is stored in the file:
    qg_image11
  2. You can also filter the data to show only certain things by using
    the expression calculator: qg_image12
  3. For example, you can see neighborhoods with less than 10 square
    miles large, by using “sqmi < 10” qg_image13
  4. Both in the table and map, the yellow rows are what is less than 10 square miles:

qg_image14qg_image15

  1. You can clear the selection by clicking clear:
    qg_image16
  2. If you want, you can go ahead and remove the layer if you’d like.

Taking data out of QGIS

Sometimes you want to take data out of QGIS to manipulate it in other software, such as Excel. You can do so, by opening the layer properties and clicking save as:

qg_image17

You can now choose a file type and name, make sure to select “CSV”:

qg_image18

Add a CSV file in QGIS

Start by clicking the comma: qg_image19

After finding the file, a new dialogue box will show up. Be sure to have Lat and Long selected for the X and Y values [X is always Longitude and Y is always Latitude]:

qg_image20

Spatial Joining Data

  1. Make sure you have the two layers you want to join together, in this case the LAPD_arrests_2015_january.csv and the Los_Angeles_ZipCodes.
  2. Go to Vector in the menu
    qg_image21
  3. Then Data Management
    qg_image22
  4. Then Join Attributes by Location
    qg_image23

5. The target layer should be the layer you want the data to go towards, the join layer is the layer you are taking the information from. So in this case, the Target is the Los Angeles ZipCodes, while the Join is the LAPD_arrests_2015_january.

  1. Make sure to choose “Intersects” for the Geometric Predicate.
  2. Be sure to select “Take a summary of Intersecting Features” and you only need “sum” and “mean” for the Statistics field.
  3. Your text box should look like the following:
    qg_image24
  4. Click “Run” to run the join.
  5. A new layer called “Joined Layer” should show up:
    qg_image25
  6. Go ahead and open the attribute table and see if the “sum” worked!
  7. Try and visualize the data like so:

qg_image26

Exporting a map

QGIS has a tool called “Print Composer” to take care of all your map printing needs. You can find it by going to “File” then “New Print Composer”

qg_image27

After opening a new print composer, you should add a map, which can by done by going to “Layout” then “Add new map”:

qg_image28

Draw a box to add your map: qg_image29

qg_image30

You can also add text, shapes and other content.

When you are done using QGIS, you can save your project as a QGIS file:

qg_image31