Joining Attributes to Spatial Features
- Starting to think about projects and searching for pertinent information
- devising a model to solve a geographical problem
- Access to Spatial and Attribute data through the UNBC Library
- Defining Stats Can boundary files and connecting data to them
- Building a query that exemplifies our model
- Visual overlay of data
- Solving a Problem
- Lit Review to get ideas
- Establish a project idea
- Data for the Project
- We are going to example this by:
- Grabbing some stats can data
- Calculate populations densities
- Exporting our work to Google Earth
Solving a Problem
We have been working toward gaining some understanding of the many aspects of spatial data, and how descriptive information can be linked to these geographical entities. Today we are going to take a break from GIS theory and concentrate on GIS applications. This is where we start to think about the mechanics of applying GIS tools towards your project ideas. In lecture it was mentioned that your projects should be laid out similar to that of a research journal. It is not important what journal you use as a template, as many are laid out in a similar fashion. We will discuss a typical journal layout in a future tutorial. This lab will not be as involved as your project but it brings together what you have learned so far to aid you in forming an idea of how to approach your project.
The first thing you need to do is review what others have investigated in regards to your topic (or get an idea as to what you may be interested in). This does not suppose that you have already determined your line of investigation but rather is intended to give you direction. It may be wise to look to google to get a quick idea of possible concepts. For instance look to google to search out: GIS and: medical, public health, or heath.
Here is a sample question (tow part) to get you going..
Question 1). Who is Dr. John Snow and what contribution did he do towards epidemiology and illustrating GIS before its modern digital use.
Now do a lit search through articles in the library for an article by Timothy Nyerges about GIS and society. Note the authors and publication date in your answer (both searches necessary for question 1).
Devising a Project
We will work with Stats Can data to test a simple theory of how well distributed hospital locations are in regards to preconceived medical notions. We are going to assume that we have done our background research (lit review) and we are going to build a model based on population descriptors expressed spatially. We are going to look at the distribution of people within parcels of B.C. We then will look at the distribution of hospitals in these areas.
Lets open up QGIS. For todays lab, adjust some settings in the software:
- Open the Settings menu and select the CRS tab on the right
- Click on the “Don’t enable ‘on the fly’ reprojection if layers have a different CRS” button (fist button)
- Click “OK”
Go to L:/GEOG204/lab_3 and load up the three datasets listed below
Arrange your layer manager (theme manager) so that both layers are visible. Pretty ugly projection for the map! We will discuss projections in a tutorial later on this semester.
Check out the illustrated glossary to find a description of this census layer at Stats Can illustrated glossary . We reviewed these small area stats can boundaries in last weeks lecture, and we will review these more in our next lecture.
Question 2). What is DA an acronym for? What parts are combined to record a DA as a geographic code? Provide an example code for a DA in Prince George?
HINT: We will be reviewing this in the next lecture, so if you are stumped – wait until the lecture.
Aggregation of stats can data (a different geographical level of stats can data
We will be taking a second look at how Stats Can boundaries are related in lecture, but today we will use attributes to get a better understanding of how smaller units can be aggregated to larger census units.
We can aggregate individual DA units into larger community based conglomerates (such as Fraser Fort George Regional District) to determine the population ratios hospitals have to support by using several methods. Today we are going to use the table joins and thematic maps. In the next tutorial we use methods that may be more difficult but very useful to know.
Before we aggregate data, review the table for the dabc layer. What are the items in this table? Do they have some meaning to you? Can you determine which of the data set has a unique identifier and what it is? Can you determine if this identifier is a character (text type) type or numeric type (by looking to see which side of the cell the values are aligned with)? If you chose the “DAUID” as the unique ID based on your knowledge of Stats Can geography naming – does it work as a UID in a GIS table (are all the values unique)?
Zoom into Prince George. Use the information button or the select feature tool – and click on a DA unit in the city.
Question 3). Three parts for 2 marks
Some of the values are not unique for DAUIDs – why is that?
HINT: In the attribute table find two DAUID values that are the same, highlight them both (remember using the crtl key to select several values), then zoom to the selected values (there is a zoom to selected button)
Why are there ‘NULL’ values for DAUID and other attributes?
HINT: What is one of the cons for using DA units for research.
Based on the Dauid value, determine the Census Division value for Prince George. From this, explain how to aggregate all the DA units into a Census Division (CD) based on the Dauid (the concepts not the QGIS commands).
HINT: Write up the steps you take below:
Using the query function to aggregate DA units to a CD unit
We need to use the query functions in the attribute table for the “dabc” layer. Ping, Jose or Emily will illustrate – as you have not queried in QGIS before. There are some helpful hints for this such as:
- you can use a numeric column (aligned to the right) with operators such as > or < with the conjunction operator AND to squeeze out the Fraser Fort George Polygons.
- you can use the operator LIKE in front of brackets containing character values (aligned to the left) with the % sign following the characters you know you want to select out.
- another way to query is to use column filter (in the pull down menu in the bottom left) for DAUID and just type in the value you are searching for. Once you have performed the query and selected the values from the table – you should have something that looks like this click on the image to see larger image):
Saving your selection
Save this newly created subset (the Fraser Fort George CD) as a new shape file in your lab3 directory. You have created a lab3 directory – right?
See if you can determine how to export to this selection to a new file, otherwise ask for help.
New Boundary data and Attributes for your aggregation
We download census attribute data in tutorial this week (for the Fraser Fort George Regional District) through the use of the census analyzer. You can practice this now if you wish. For today’s lab we will use the data provided in the next section.
For this lab we will use all of statistics for B.C. to match to the new Fraser Fort George CD. Can we do this – the table from Stats Can will have many more records (rows) than the attribute table for the CD layer?
Download a Boundary file for the lab from Stats Can.
There are many pages on the Stats Can site, and navigation to find specific data can be a bit daunting. It is easy to find a link to the Boundary files by just doing a google search for them. We are interested in:
- 2016 boundary files for Dissemination Areas
- the English data
- in shapefile format (shp)
- you can download either the boundary or cartographic file
Once you download the data (a compressed zip file) into your lab3 folder:
- navigate to the file
- right click to decompress the files into your lab 3 folder
- add the data new layer into QGIS
Zoom back into the area around PG. Notice the difference between the shapes of the polygons between the layer you loaded from the lab folder to the new file you have downloaded.
Subset the BC DA polygons
The census data gathered for the section below is for BC only. With this in mind, we should create a new shapefile from downloaded dataset that has only the BC polygons.
We are not going to tell you how to do this – as this action is very similar to the steps you took to perform the extraction of the Fraser Fort George polygons above (except easier).
Joining census values to boundary files
To keep us all on the same page, we will use the data prepared for the lab (a non-spatial *.csv file for importing into QGIS). This file was downloaded and cleaned in the same manner as we did in the tutorial (except it is not an excel file, but a CSV – Comma Separated Value).
Add da_pop_all_of_bc.csv from
into your project, and join the two tables together (your new CD layer and the CSV file) in the following manner:
- Right click on the layer and open its properties
- Go to the joins tab
- select the layer to join –> the fields to join on
- Choose the fields that are joined to the table
- Set the Custom field name prefix to be empty as the image shows below:
Calculate population density
Once you have joined the data together – open the data and observer that some of the population values are “0 or n/a”. What could cause these values to be in a DA census set?
Clean your data to remove “n/a” value
Now that you are a great query builder, find any polygons that have an “n/a” value and delete them. Once selected you can hit the read garbage can to delete the row.
Calculating the area to your DA polygons
We also need an area for the polygons to calculate population density.
This can be accomplished by the following steps
- Open the attribute table of the layer
- Find the field calculator button and launch the calculator
- Setup a new field called area as a decimal number with an output length of “20” precision of “2”
- Use the “$area” geometry function to populate this column
- Use the image below as your guide
Calculate population density
Now that you have population values and area. calculate the population density of the polygons in square kilometres by:
- opening up the field calculator and create a new field
- cal the new field called popdense
- Decimal number with precision 2
- use the calculation
- pop / (area /1000000)
Save you edits to the shapefile
Export your results to Google Earth
Style your Census Division values
As you did in the first lab, style your bc DA layers using the “catatgorized” with your population field as the field to classify with. Here is a quick reminder as to how to do this:
- Right click –> properties
- Click the style tab and switch to catagorised from single symbol
- Use the CDUID column
- Hit classify
- Apply and OK
This is really not a good looking map, but it will work for what we need to do today. A better map would be to use the graduated styling method using the population values. In order to do this, you would need to change the population values to integers instead of text values.
Export the data to Google Earth
You can export data to Google Earth (KML file) at any time using the right click –> save as method – BUT this method does not save the styling for polygons. We are going to use another plugin to get the styling as well.
Plugins: Add the plugin mmqgis to your project
Here are the steps to export the map to Google Earth
- Add the mmqgis plugin as usual
- Click mmqgis menu –> Import/Export –> Google Maps KML Export
- Choose the CDUID as the Name Field
- Click APPLY
- Wait until the bar turns blue giving you the number of polygons
- Hit CLOSE
Now Open up Google Earth and load the KML file into it
- Open Google Earth –> Menu –> Internet –> Google Earth
- File –> Open –> browse to your KML file
Question 4: 1 Mark
Take a screen shot of your google earth creation and paste it into your word file for this weeks lab assignment.