Skip to content

Lab 1.2 “Hello World!” QGIS Bootcamp

Adding spatial data

Important: Before starting this lab, you must have completed the pre-lab and part 1. This means you should have already installed QGIS and a local copy the lab.

  1. Click on Layer

  1. Add Layer Add vector layer

  1. Locate the file **CA_Counties.shp**

  1. Click Add to add it to your QGIS project.

  1. Counties in California should now appear:

Exploring spatial data attributes

  1. In the Layers panel, right click on the layer **CA_Counties_TIGER2016**

  1. Click on Open Attribute Table

  1. Now you can see the attributes of each of the spatial data shown in the map:

  1. You can click on the headers to sort, so let’s find the most populous county in California by scrolling to **TOTAL_POP** and clicking on it:

  1. We can highlight the county by click on the number box with the number 1 next to it:

Note: Shift + Click down to select multiple rows:

  1. Return to the map to see the most populated counties according to the American Community Survey 2019 data in California highlighted:

  1. Clear your selection in the following ways:

    1. Clicking the deselect button in the general interface:

  1. Or the deselect button in the attribute table:

Adding a field

Since bigger areas are most likely to have more people, we need to factor that in to see where most people in the state are likely to be found. We will do a population density calculation, which is simply number of people divided by total area.

  1. Click the edit tool to enable making changes:

  1. Warning! When you are in editor mode you can click on any cell to directly edit it:

  1. If you accidentally made edits, turn off editing mode by clicking the pencil again:

  2. Choose Discard:

  1. Next click the Field Calculator button:

  1. The field calculator window will appear:

  1. Click on Output field name and type in AREA_SQ_KM which will be Area in square kilometers.

  1. Click on field type and choose Decimal Number (real)

  1. In the Expression box type in the following:
  • $area / 1000000

  1. If correctly done, you can see the preview will show the value:

  1. Click OK:

  1. You can see our new field all the way on the right side:

  1. Open the Field Calculator again and create a new field called POP_DENSIT with Decimal number (real):

  1. Locate the search box, this place is helpful for creating expressions.

  • In the search box type in total_pop and double click on the result:

  • Note: The help on the right side explains more detail about what is being selected in the search box.
  1. Add a / for divide

  2. Search for area_sq_km and add it to our expression:

  1. The final expression should be:

"TOTAL_POP" / "AREA_SQ_KM"

  1. Check the preview:

  1. Hit OK:

  1. Check to see if the POP \ DENSIT column is there:

  1. If you have successfully calculated the population density for all the counties in California, then click the save button to save our edits:

  1. Turn off the editing tool as we are done with it:

Symbolizing our map

  1. Right click on our layer and go to Properties:

  1. Click on Symbology:

  1. From there, click on Single Symbol to change which data fields are being used for map creation:

  1. If we were working with qualitative data fields then we would use categorized, however we are going to be looking at our population density data field, so we should use graduated:

  1. Click the dropdown arrow near Value to see the list of fields:

  1. Choose POP_DENSIT:

  1. Change the Mode to Equal Interval which means that the breaks between values are evenly spaced apart (i.e. 0-5, 5-10,10-15):

  1. You can click histogram to get a better sense of the data and which statistical mode you should use (but since this is not a stats class, I won’t spend much more time on this):

  1. You can also change the number of classes (or breaks) by clicking here:

  1. Click OK to apply our changes to the map:

  2. You can change the colors by clicking on Color ramp:

  1. Or individually by right clicking the square colored boxes:

  1. Choose change color and adjust the color wheel:

  1. When satisfied with your changes click OK to close the dialogue box:

  1. You map should look like the following:

  1. Tip: You can quickly change any color by right clicking on the colored box to the left of any layer:

Filtering our fields

  1. Let’s do some advanced filtering to see places where more than 100,000 Asians live.

  2. Start by opening our attribute table again:

    • Right click on our layer
    • Click Open Attribute Table:

  1. Click the Filter selection form.

  1. We are finding places with Asians so locate the ASIAN_POP field:

  1. Click the Exclude field button to change it:

  1. We will make it Greater than or Equal to:

  1. Then type in 100000:

  1. Click on Select Features

  1. Click the lower right icon to return to the table view:

  1. You can view only selected features by clicking here:

  1. Then choosing Show Selected Features

  1. Close the table when done exploring by clicking the X:

  1. Congrats! Now you have filtered some features.

Saving Our Map Layer for Web Mapping

  1. With everything still selected, right click on the layer:

  1. Go to Export and then choose Save Selected Features As…:

  2. The ESRI shapefile is the default, but it is very hard to use in our web applications because it is a proprietary data format..

  1. The preferred spatial format online is a GeoJSON file:

  1. Click the next to File Name to find a nice new home for your GeoJSON file!

  1. Your final box should look like this:
  • Format: GeoJSON

  • File name: CA_counties_with_over_100k_Asians.geojson

  1. Congratulations! You have created your first GeoJSON file! We will revisit this file in next week’s lab, so keep it safe and sound!

Adding non-spatial data

  1. You can also add CSV files by clicking Layer

  1. Click on Add Layer Add Delimited Text Layer...

  1. To the far right of File Name, click on the button with :

  1. Locate the file for California Asian American Hate Crimes, CA_AAHC_2021.csv and select it and choose Open:

  1. Check to make sure Point coordinates and a coordinate reference system exists:

  1. Click Add and then Close:

  1. The data points should now show up:

  1. Note that you will not be able to edit CSV files, you will need to export them in a spatial data type format, such as shapefile or GeoJSON to do so.

  2. Congratulations on finishing the spatial data management QGIS bootcamp.

Lab Questions

Please take some time to think about the following questions, they may be helpful when you are posting your Thinking Cap response for this week.

  1. What changes did we make to the original data?

  2. How can the choices we made in changing the data be problematic?


Last update: 2022-01-24
Back to top