Introduction to QGIS - House Hounting Plan

Get started with QGIS

Overview

Teaching: 20 min
Exercises: min
Questions
  • How do we add a vector data into QGIS?

  • How do we map X and Y Coordinate into QGIS?

  • How do we add a basemap and a plugin into QGIS?

Objectives
  • Know how to add vector data into QGIS.

  • Know how to add delimited file into QGIS and map them.

  • Know how to add a basemap into QGIS.

  • Learn how to add a plug in into QGIS

Familiarize yourself with QGIs

1.The main area of QGIS is called the canvas. There are also panels and toolbars, a status bar and menu panels.
2.Panels and toolbars may be moved around and docked at different locations (left-click and hold to initiate this flexibility). If you drop a panel on top of another, they will be nested into tabs. Panels you do not used can be removed. Toolbars can be moved around in much the same way, but you cannot nest toolbars into tabs. By right-clicking in the toolbar area, you may get a list of available panels and toolbars you can turn them on and off as you like. 3.Through the menu, you can access almost everything in QGIS; some functions have buttons, and keyboard shortcuts as well. 4.The status bar shows relevant information about the current tool or aspects of the map canvas, like coordinates and scale. 5.Toolbox is where you can search for all the tools provided in QGIS. If you can see the toolbox as the figure shows, you can open it in the menu (Processing->Toolbox).

QGIS Layout

6.Use the map navigation toolbar to help navigate your map in the canvas. Here you can find tools to pan and zoom the map, zoom to selected features, and view the complete extent of the map or selected layer. You can also jump to a previous extent with dedicated buttons.
QGIS Toolbar

Add data to QGIS

To start, we need to download the data first. There are two shapefiles: Grocery stores Download, and Neighborhood boundary Download, and a csv file: Apartments Download.

Add vector data

  1. a. Left-click the “Layer” menu option, hover over “Add Layer,” and left-click the “Add Vector Layer” option.

Add a vector layer

2.In Data Source Manager Vector window, click the button and navigate to the folder where the data is. Once select GroceryStores_sp.shp, click Add.

Add Grocery store layer

3.Follow the same procedure and Add Neighborhood_sp.shp.

Add Neighborhood layer

  1. After adding GroceryStores_sp.shp and Neighborhood_sp.shp, close the Data Source Manager Vector window.

Add delimited file

QGIS can convert X Y Coordinates into locations on a map. Open Apartments.csv and you can see X_Coor and Y_Coor columns. These are geospatial information for these apartments. We can map X_Coor and Y_Coor as a point layer in QGIS.

  1. In the menu bar, click Layer, then Add layer, and choose Add Delimited Text Layer.

Add delimited file

  1. b. In the Data Source Manager Vector window, 1) navigate to the Data folder and 2) choose Apartment.csv. 3) Make sure Geometry CRS is EPSG: 4326 – WGS84. 4) Click Add. Close the Data Source Manager Vector window. Apartments should show in the Canvas.

Add Apartments layer

3.The Canvas looks like the following. There are two points layers (Apartments, and GroceryStore_sp), and one polygon layer (Neighborhood_sp).

Layout after adding layers

Add a basemap

QGIS provides access to a variety of online base maps. You can add these base maps by building XYZ Tiles connections. Here we add Google Road/Streets as the base map for the project.

  1. Find XYZ Tiles in Brower. Right click XYZ Tiles.

Add a new connection of XYZ Tile

  1. In the XYZ Connection window, name the new XYZ Tile as Google Road/Streets, and copy https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z} into URL. Click OK.

Add Google Streets as the basemap

  1. Drag Google Road into the Canvas and move Google Road layer to the bottom in Layers Panel.

Drag Google Streets to the Canvas

Add a plugin

As an open source software, QGIS have an active community constantly contributing to a variety of tools by developing QGIS plugins. We will use a MMQGIS plugin in this project.

  1. To add a plugin, go to Menu, and click Plugins. Then click Manage and Install Plugins.

Manage and install plugins

  1. In the Plugins window, search for MMQGIS. Click the mmqgis and then Install Plugin. MMQGIS plugin

  2. After installation, check the box in front of mmqgis.

Check mmqgis plugin

  1. With successful installation, you should see the MMQGIS in the Menu bar.

Open MMQGIS in the Menu bar

Key Points

  • Vector data use X and Y coordinates to define the loctions of points, lines, and areas (polygons) that correspond to map features.

  • To map a delimited file, the file need to have geospatial information (e.g. X Y Coordinates).

  • X Y Coordinates are longtitude and latutide in degrees. WGS 84 is the most often used geodetic datum to represent coordinates

  • A variety of basemap can be added to QGIS through adding an XYZ Tile layer.


Spatial Analysis in QGIS

Overview

Teaching: 40 min
Exercises: 0 min
Questions
  • How can we find apartments that meet the student’s criteria?

Objectives
  • Understand what projections are.

  • Project a layer under a suitable projection.

  • Be able to creat buffers.

  • Be able to count points with buffers.

  • Be able to join attribute tables.

  • Be able to select features by attributes.

Projection

Before we do the spatial analysis to find the suitable apartments, we need to project the Aparments layer. The Apartment layer is converted from a csv and the locations are derived from X and Y coordinates. X and Y coordinates are longtitudes and latitudes which represent locations on a global. We need to project the locations onto a “a flat piece of paper” before we do the analysis.

Projecting a map into different projections means drawing the earth surface onto a “a flat piece of paper”. There are a variety of methods to “draw”, among which there are three major methods: planar (left), conic (middle), and cylindrical (right) projections.

Different Projections

Different Projections Source

The Apartments layer we mapped into QGIS canvas are locations represented by X and Y Coordinates (latitude and longitude on the Earth surface). To analyze the layer, we need to project the Apartments layer from latitude and longitude (unit in degrees) to a “flat paper” using a suitable method. We will project the Apartments layer into NAD83(2011)/California Zone 5.

  1. Go to Processing Toolbox and search for projection. If the Processing Toolbox does not show on the right panel of QGIS layout. Go to the Menu, Processing, and Click Toolbox.
  2. Select Reproject Layer.

Reproject lyaer

Reproject layer

  1. In the Reproject Layer
    • (1) choose Apartmets
    • (2) click the button to select projections
    • (3) type in 6432 in the Filter
    • (4) choose NAD83(2011)/California zone 5
    • (5) Click OK
    • (6) After the configuration, Cilck run.

Find NAD83(2011)/California zone 5 projection

Find NAD83(2011)/California zone 5 projection

  1. Once the projection is done, you can find there is a new layer named Reprojected showing up in the Layer panel.

Rename the reprojected layer

Rename teh reprojected layer

  1. Rename the Reprojected layer as Apartment_sp. Sp means State Plane, which is the projection system specifically for United States. NAD83(2011)/California zone 5 is a part of State Plane Projection.

Rename the layer

Rename the layer

Save the reprojected layer

  1. Looking at the renamed layer: Apartments_sp, you can find there is a button (looks like a caterpillar). This button indicates the layer is a temporal layer and is not saved. To save this layer, click the “caterpillar” button, a Save Scratch Layer window pops up.

Save the scratch layer (a)

Save the scratch layer (a)

  1. Name the file as Apartments_sp and save it in your working folder. Click OK.

Save the scrath the layer (b)

Save the scratch layer (b)

  1. After saving the layer, go back and check the Apartments_sp in the Layer panel. The “caterpillar” button disappears, indicating the layer is saved.

Save the scratch layer (c)

Save the scratch layer (c)

To find out which places are suitable for the student, we set two criteria:

  1. there are at least 2 grocery stores within 400 meters of the buffer centered at the Apartments.
  2. Price is less than $1300. According to a study, a distance of 0.25 miles is often used as an accepted in U.S. research studies. We set 400 meters as the walking distance to make buffers around apartments. The price is set arbitrarily. You can set different price thresholds to compare the different result.

To meet the criteria, we need to

  1. make 400 meters distance buffers centered at apartments
  2. count the number of grocery stores with the buffers
  3. join the buffer’s attribute to apartments layer
  4. select the targeted apartments

Create walking distance buffers

  1. Go to Menu bar and find MMQGIS (the plugin installed). Click Create Buffers.

Create buffers

Create buffers

  1. In the Create Buffers window
    • (1) select Apartments_sp. This is the layer that we will center to create buffers.
    • (2) Set the radius as 400
    • (3) Unit is meters
    • (4) Click the button to save the buffers.
    • (5) Save as buffer.shp
    • (6) Click OK.

Creat buffers around Apartments_sp

Create buffers around Apartments layer

  1. The buffer layer should show up in the Layer panel.

Buffer in the layer pannel

BUffer the layer panel

Count points within buffers

1.In the Menu bar, find Vector. Go to Analysis tool and Click Count Points in Polygon.

Count points in polygon (a)

Count points in polygon (a)

  1. Select buffer for Polygons, GroceryStore_sp for Points. Then go to Count and Click Save to File.

Count points in polygon (b)

Count points in polygon (b)

  1. Navigate to the Save the output as GroceryCount.shp. The saved file should show up in the Layer Panel.

Save the GroceryCount layer

Save the GroceryCount layer

Join attribute layer

We counted the number of grocery stories with each buffer, and the information is stored in GroceryCount Layer. Let’s check the attribute table, find the information (NUMPOINTS) and join the attribute table to Apartments_sp.

  1. Right-click GroceryCount and Open Attribute Table.

Open attribute table

Open attribute layer

  1. There are 5 attributes (columns) in the table, and the last one is NUMPOINTS. This is the number of grocery stores in each 400 meters buffer.

Attribute table of GroceryCount layer

Attribute table of Grocery Count layer

  1. To join GroceryCount’s attribute table to Apartments_sp, we need to
    • (1) open Apartments_sp attribute table
    • (2) find the shared column, and join. Right click Apartments_sp and Open Attribute Table.

Open attribute table

Open attribute table

  1. Comparing the two attributes tables, both GroceryCount and Apartments_sp have Address column. We will use Address as the shared column to join these two tables.

Attribute table of Apartments_sp layer

Attribute tbale of Apartments_sp layer

  1. Go to Processing Toolbox, and type in Join in the search bar. Select Join attributes by field value.

Join in Processing Toolbox

Join in processing Toolbox

  1. In the Join Attributes by Field Value window, choose Apartments_sp as the Input Layer and Address as Table field. Choose GroceryCount as Input Layer 2 and Address as Table field 2. Click Run.

Join table by field value

Join tables by field value

  1. A Joined Layer shows up in the Layer Panel. Right-Click it and rename the layer as Apartment_GroceryCount.

Figure 42. Rename Joined layer

Rename Joined Layer

  1. here is a “caterpillar” button, indicating this is a scratch layer that is not saved on local drive. To save it, click the “caterpillar” button and save it as Apartment_GroceryCount.shp.

Figure 43. Save Apartements_GroceryCount

Save Apartments_GroceryCount

Select feature class by attributes

To select by attributes, we need to open attribute table and look at how many attributes the table has and which attribute we will analyze.

  1. Right click Apartments_GroceryCount and Open Attribute Table.

Figure 44. Open attribute table of Apartments_GroceryCount

Open attribute table of Apartments_GroceryCount

  1. There are total 443 records with 11 columns (attributes). Click the Select feature using an expression.

Figure 45. Select by expression (a)

Select by expression (a)

  1. Go to Expression tab. There are three panels in the window, expression (left), a list of functions (middle), and explanation of functions (right). Choose functions from the middle panel.

  2. Click the functions from Fields and Values and Operates in the middle panel and make the expressions: “NUMPOINTS” >= AND “Price” <= 1300. Then click Selected Features.

Figure 46. Select by expression (b)

Select by expression (b)

  1. You can see the selected features are highlighted in the Canvas. There are 2 apartments selected.

Export teh selected feature class

  1. Right click the Apartments_GroceryCount. Choose Export and click Save Selected Features As.

Figure 47.Save selected feature (a)

  1. Save the selected features as Apartment_Selected.shp. Click OK.

Figure 48.Save selected features (b)

Save selected features (b)

Invert Selection

Saving the selected apartments, we Invert selections and export the apartments that are not selected. We need the unselected apartments for mapping later.

  1. In the attribute table, click the Invert selection button. The selection changes into the rest of the unselected apartments.

Figure 49.Invert selection

Invert selection

  1. Export the new selection as Apartment_NotSelected.shp.

Figure 50.Save selected features (c)

Save selected features (c)

Figure 51.Save selected features (d)

Save selected features (d)

Deselect the selected feature class

After exporting Apartment_Selected and Apartment_NotSelected, go to the Tool bar in QGIS and Click Delected Features from the Current Active Layer. This will deselect the selected features in Apartement_GroceryCount layer.

Figure 52.Deselect features from the current active layers

Deselect features from the current active layers

Key Points

  • Projection is the way to convert locations in a global onto to a flat plane.

  • Choosing a right projection for a study area is crucial before any spatial analysis.

  • The radius of created buffers is measured by Eucilidean distance.


Change layer properties

Overview

Teaching: 15 min
Exercises: 0 min
Questions
  • How do we change symbology of layers?

  • How do we add lables to layers?

Objectives
  • Know how to Change symbology of layers.

  • Know how to add labels.

Next, we will change the layer properties:

  1. change the symbology
  2. label the map.

Symbology

  1. Right click Apartment_Selected and choose Properties.

Figure 53. Open Properties window (a)

Open Properties window (a)

  1. Select Single Symbol. Click Marker and select effect drop shadow.

Figure 54. Change symbol (a)

  1. Select the second Simpler maker and remove it.

1Figure 55. Delete the Single Marker

  1. Switch to Apartment_NotSelected layer and open Properties.

Figure 56. Open Properties window (b)

  1. Also select Single symbol. Choose diamond green.

Figure 57. Change symbol (b)

  1. Select the Simple Marker. Go to Fill color and check Transparent Fill.

Figure 58. Change the Single Marker (a)

  1. Change the symbol of GroceryStore_sp. Go to the Properties.

Figure 59. Open Properties window (c)

  1. Follow the similar procedures of changing the symbol for Aparment_Selected to change the Marker for GroceryStore_sp. Choose dot orange and make the marker transparent.

Figure 60. Change symbol (c)

Figure 61. Change the Single Marker (b)

  1. Change the symbol for Neighborhood_sp layer. Open properties. Choose Single symbol and click Simple fill. In Fill color, check Transparent Fill.

Figure 62. Change the Simple Fill

Add labels

We want to label the selected apartments with the prices.

  1. Open Properties of Apartment_Selected layer.

Figure 63. Open Properties window (e)

  1. On the left panel, select Labels. On the right panel, from the top select Single Label. Select Price for Value.

Key Points

  • Make the point hollow to show overlapped points.

  • Use contrasting colors to highlight the points against the basemap.


Creat print layout and Save the project

Overview

Teaching: 15 min
Exercises: 0 min
Questions
  • How do we to create a new print layout?

  • What are the basic elements for a map?

  • How do we export and save the map?

Objectives
  • Learn the basic elements of map.

  • Know how to organize the elements in a map and change the properties of the elements.

  • Know to how export the map and save the project.

Create the print layout

Changing the properties of the layers, we are ready for making and exporting a map.

  1. In the Menu, find Project and choose New Print Layout.

Figure 65. New print layout

New print layout

  1. Name the print layout as House Hunting Plan

Figure 66. Name the new print layout

Name the new print layout

  1. The layout of the Print Layout.

Figure 67.Layout of the new print layout

Layout of the new print layout

  1. Use the tools in the Toobox bar to draw rectangles in the Canvas and add different elements for a map, such as title, map, legend, north arrow, and scale.

Figure 68. Add elements to make map

Add elements to make a map

    • (1) Click Select/Move item button in the Toolbox bar
    • (2) select the title.
    • (3) In the Properties panel, change the title as House Hunting Plan.
    • (4) Move blow and change the Font to fit the map. If there is no change after changing the properties
    • (5) click refresh.

Figure 69. Change properties of the title

Change properties of the title

  1. Scroll down the Properties panel, select Center for Horizontal alignment and Middle for Vertical alignment. Check Frame to add the frame to the title.

Figure 70. Center the title horizontally and vertically

Center the title horizontally and vertically

Figure 71. Add frame to the title

Add frame to the title

  1. Select the map and add a frame to the map in the Properties panel.

Figure 72. Add frame the map

Add frame the map

  1. Click the legend and change the properties of legend. Uncheck Resize to fit contents and Auto update. Delete some layers and only keep the layers we want to show in the map: Apartement_Selected, Apartment_NotSelected, GroceryStore_sp, Neighborhood_sp, and Google Road.

Figure 73.Customize the legend (a)

Customize the legend (a)

Figure 74. Customize the legend (b)

Customize the legend (b)

  1. Rearrange the positions of the elements (title, north arrow, scale, legend, and map) to make a nice map.

Export as Pdf, image or SVG

The map can be exported/saved as image (jpg, png, etc.), SVG (a format using for html file), and pdf. We save the map as an image (jpeg) for this project.

Figure 75. Export the map

Export the map

Save the project

We did a simple spatial analysis and made the first map! Good job! Next step is saving the project.

  1. In the print layout window, click Layout in the Menu bar. Save Project. This will save both the edited map and the print layout.

Figure 76. Save the project from print layout view

Save the project from print layout view

  1. Another way to save the project is: switching back to QGIS layout view, choosing Project and Save the project as HouseHuntingPlan.

Figure 77. Save the project from main menu

Save the project from main menu

Figure 78. Save the project as HouseHuntingPlan

Save the project as HouseHuntingPlan

Key Points

  • The basie elements for a maps are scale, legend, north arrow, title, and the content.

  • You can save the map in three types: pdf, image, and SVG.