In this guide you will learn how to use QGIS to make a map. The objectives of the guide are as follows
QGIS (or Quantum GIS) is an open source geographic information system, meaning that it can be downloaded and installed on your desktop free of charge. It runs on Windows, Mac OS X, and Linux. If you have used ArcGIS before, which all UC Davis affiliates have free access to, QGIS is very similar except that it has less functionality but is free for everyone and can be used on a Mac without having to rely on a virtualization software program like Parallels. QGIS is not like R in that its data processing and analysis capabilities are more limited. But, QGIS is, in my opinion, a better program for making a map. It is quicker to make a map in QGIS compared to R, allows more user efficiency and control over mapping aesthetics, and produces nice looking maps with relatively little cost in time, effort and learning curve. This is not to say that you should not use R for mapping. If you master spatial R, you can make some really cool maps with R. But, if you need to quickly make a nice looking map, QGIS is a great tool to have in your back pocket.
You can download QGIS from its official developer website. I generally recommend using the most recent Long Term Release over the most recent version of QGIS. Long term releases might not have the newest features, but has fewer bugs and is less glitchy than the most recent release. The current long-term release is 3.10. For Windows, this will be labelled QGIS Standalone Installer Version 3.10. For Mac, this will be labelled QGIS macOS Installer Version 3.10.
This tutorial is based on QGIS version 3.10 for Windows. The guide’s instructions should not significantly differ across Mac and PC versions. However, installation instructions do have some key differences.
Windows users: You will need to choose between the 32-bit or 64-bit versions based on your particular operating system. If you don’t already know which one you have, you can figure it out.
Installation is pretty simple. Follow these steps:
From the QGIS download site, click on the appropriate 32- or 64-bit QGIS Standalone Installer Version 3.10
Click on the downloaded .exe file.
The installation wizard window below should pop up. Click Next.
A License Agreement window will pop up. Click on I Agree.
Choose an appropriate location on your hard drive to save QGIS. The default (Program Files) should be fine.
Don’t alter anything on the Choose Components page. Just click on Install. Wait a bit for it to install. A final window will pop up. Click on Finish and you’re all good.
Mac users: The method for downloading QGIS on a Mac will depend on the version of the operating system (OS) that your computer is running on. To find out your current Mac OS, click on the Apple icon located at the top left of your screen and then select About This Mac. A window should pop up giving your Mac’s current OS.
If you are running High Sierra (10.13) or newer, follow these simple directions:
From the QGIS download site, click on QGIS macOS Installer Version 3.10 and save the file in an appropriate location.
Click on the downloaded .dmg file
Next screen, click on Agree
The funky looking screen below should pop up. Click and drag the QGIS3.10 icon to the Applications folder. After that, you should be all good.
If you have an earlier Mac OS version, you’ll have to download an earlier version of QGIS. If possible, update to a more recent Mac OS version, as QGIS no longer fixes any bugs for its older versions. However, if you’re afraid of updating your OS, click here to download an older version of QGIS. You should see all previous versions of QGIS. If your computer is super old, download QGIS 2.18.28.
Unfortunately, installation for older versions of QGIS is not as simple. Before you run the installer, you’ll need to make sure you can add new software to your Mac. Go to your System Preferences (under the Apple menu), and click on “Security & Privacy”. Click the lock icon in the bottom left to make changes. For the section titled “Allow apps downloaded from:”, Check the “Anywhere” radio button. Now you are ready to install. When you open the disk image that you downloaded, you’ll see the following files.
First thing to do is to read the Read Me.rtf file. You must install Python, GDAL, and QGIS in that order. Installing separate components like this can seem a bit weird if you’re not used to installing open source software. For 3.4 and later versions, QGIS packaged all of these installations into one quick download.
We’ll be working with Sacramento county tracts in this lab. Go to the Week 10 Canvas folder and download the zip file qgisdata.zip onto a convenient place on your hard drive that you can readily access. Unzip the folder. The folder will contain the following shapefiles and csv files.
Open up QGIS. You should see an interface similar to Figure 4.
The components of the interface are as follows
Let’s bring in the shapefile of Sacramento county tracts. This is like st_read()
in R. You can bring in a shapefile in one of the following ways.
Let’s use the Data Source Manager approach. When you open up the Data Source Manager, you should get the following window
We want to bring in a shapefile showing Census tracts in Sacramento county. Tracts are polygon or areal data, also known as Vector data. From the Data Source Manager window, follow the steps outlined below.
We got a shapefile into QGIS. Hooray for us! Let’s now map a variable by bringing in some data to map. Bring up the Data Source Manager and follow the steps below to bring in a csv file into QGIS. This is like read_csv()
in R. The file contains tract-level percent Hispanic (phisp) and percent poverty (ppov).
We now want to join (merge) the csv data (tract_demographics) to the shapefile (Sacramento_County_Tracts). This is left_join()
in R. To do this, follow the steps below.
Check the Custom field name prefix box - a white box should pop up underneath - delete the text (tract_demographics_). If we did not do this, the variables phisp and ppov will be named tract_demographics_phisp and tract_demographics_ppov in the Sacramento_County_Tracts file, which are too long. By deleting it, we’ll keep the names to phisp and ppov.
The Add Vector Join window should look like Figure 14. Click OK. Click OK again in the next screen.
To verify that the join worked, you can open up the attribute table for the shapefile. An attribute table consists of rows representing spatial features (census tracts), and columns representing properties or characteristics of the spatial feature (e.g. percent Hispanic). It’s a nonspatial dataset attached to the spatial dataset. To bring up the attribute table, you can either
The table should pop up and contain 317 rows corresponding to the 317 tracts we have displayed on the map screen. See Figure 15. Scroll all the way right - you should see the variables we added from tract_demographics: ppov (percent poverty) and phisp (percent Hispanic).
Joining data to the shapefile is not permanent. If you close QGIS, reopen it, and bring in Sacramento_County_Tracts, you will find that phisp and ppov are no longer in the attribute table. You will need to save a new shapefile to make this join permanent. This is like st_write()
in R. To save a shapefile, follow the steps below.
You should see Sacramento_County_Tracts_Dems pop up in your Layers panel. It should also pop up in the Map Display window in a different color. Because we only need this shapefile moving forward, remove tract_demographics and Sacramento_Country_Tracts by right clicking on each from the Layers panel and selecting Remove Layer. You can also click on the layer you want to remove and select , which is located top right of the Layers panel.
Let’s map percent poverty at the tract level for the county of Sacramento. This is like tm_shape()
or ggplot()
in R. The first thing to do is to symbolize the map based on percent poverty.
You should get something that looks like Figure 18.
We’ve symbolized our map, but now we want to create and save a map for presentation purposes. QGIS has a powerful tool called Layout Manager that allows you to take your GIS layers and package them to create and save pretty maps. Why do we need this tool? A GIS map file is not an image. Rather, it saves the state of the GIS program, with references to all the layers, their labels, colors, etc. So for someone who doesn’t have the data or the same GIS program (such as QGIS), the map file will be useless.
To create a map, follow the steps below.
You should see a screen that looks like Figure 20 pop up. This is the Map Layout screen.
Let’s go through each component of the Layout screen
To add our map, select Add Item from the Main Menu of the new screen and select Add Map.
Nothing should happen. However, your mouse cursor should look like a black cross. Move your cursor to the top left corner of the white canvas and drag it to the bottom right corner to create a rectangle. See Figure 21.
The map of Sacramento county maps should pop up. With the map now displayed, you can
The scale and extent of the map shown in the Map Layout will match what is shown in the main interface. The extent controls movement West, East, North and South. Scale controls zooming in and out. Toggle back to the main QGIS interface. If you want to make the map bigger or smaller in the Map Layout window, you can change the scale from the Status bar in the main interface. For example, the current scale I have in the main interface is . I can zoom in a little more - I can do this by using the tool or just type a scale in directly to the scale box. I do the latter by typing in, for example, 1:300000 and pressing enter.
Toggle to the Map Layout window. You will notice that nothing has changed. The scale in the Map Layout window will not update - you will have to do it manually. Click anywhere on your map in the Map Layout window. On the right panel of the window, click Item Properties, click on the button . See Figure 22.
If you move the position of Sacramento West, East, North or South in the main interface, you update the Map Layout by clicking on the Set Map Extent to Match Main Canvas Extent button
A legend is an essential feature in a map. To add a legend, follow the steps below.
If you want to customize the legend, click anywhere on the legend, and in the right panel under Item Properties a window named Legend should now be there. The panel provides different settings that you can alter to customize how the legend looks. For example, double click on Sacramento_County_Tracts_Dems under Legend items.
This should bring up a little dialog box which allows us to give the legend a more descriptive title. Delete the current title “Sacramento_County_Tracts_Dems” and type in a more descriptive title, such as “Percent Poverty”. You can change the font size and color by altering the properties under Fonts.
A scale bar is an important component of a map because it gives the viewer a visual indication of the size of features, and distance between features, on the map. To add a scale bar
Similar to legend, the scale bar properties should pop up in the bottom right panel. You can change its properties, for example going from Kilometers to (the US centric) miles and adding more segments. Here are a few changes we can implement:
So far, here’s what the map looks like.
Adding a north arrow improves many maps, especially large-scale maps that show a smaller area in great detail and maps that are not oriented with north at the top. To add a north arrow
After selecting it, you can customize as you see fit. For example, I kept the default arrow but altered the properties to make it look like
How did I make the arrow look like this?
You can’t have a map without a descriptive title. Let’s add one.
As with all features, you can customize the title as you see fit. For example, staying in Item Properties, under Appearance, I
If you need room at the top to fit the title, you’ll need to adjust the scale or extent from the main interface. My map now looks like Figure 29. Looks nice, right? Of course.
Right now, it looks like Sacramento county is floating in space. There’s nothing necessarily wrong with this - check this gallery of QGIS maps or even do a basic Google search of Sacramento poverty map and you’ll find plenty of maps without context. But, we can provide some context to the map by adding a background. We can do this by adding a base map.
A base map provides geographical context to a region of interest. For example, a base map might help viewers orient themselves to a specific county by displaying the surrounding counties. QGIS has a few preinstalled basemaps that you can add to your map. Let’s add an OpenStreetMap basemap. OpenStreetMap is a free editable crowdsourced map of the world.
In the Browser window on the main interface, click on the arrow next to XYZ Tiles. The option OpenStreetMap should show up.
Double click on OpenStreetMap. The OSM basemap should pop up both in the Map and Layout views. You’ll see that these tracts are obscuring the Sacramento_County_Tracts_Dems layer. Change the layer order by clicking, holding and dragging the OpenStreetMap layer below Sacramento_County_Tracts_Dems in the Layers panel (or move the Sacramento_County_Tracts_Dems layer above).
You should see your symbolized map of Sacramento county tract poverty pop up.
Go back to the Map Layout window. You will notice that the OpenStreetMap layer was added to the legend. To take it out
You can further customize the map as you see fit. I ended up with the map shown in the figure below.
You can add other freely available basemaps like Google Maps. For more details on how to do this, read this informative blog post.
Ultimately, you’ll want to share this map with others. You usually do this by sharing it as a jpeg or pdf. If you save it as a jpeg, you can paste it into a word document or PowerPoint presentation. To export your map
When saving a project you are not saving actual data files. That is, you are not saving Sacramento_County_Tracts_Dems. Project files do not contain maps, instead they contain information on where original shapefiles are stored and what processes are needed to recreate a map. A saved project file includes information about the path to each data layer included as well as your choices about symbology, labels, and layer order. Before closing QGIS, users should save their progress in a Project file so it can be used and edited in the future. It is important to note that all shapefiles associated with the map must stay in the same location when you first created the map. If they are moved, QGIS will not be able to locate the files and rebuild the map. To save a project
The project file will be saved as a .qgz
, which can be only opened in QGIS.
This tutorial scratches the surface of what you can do with QGIS. You can get more practice by using the official QGIS training manual here. They also have a more Gentle Introduction to QGIS
Because QGIS is open source like R, this means users can create and add to QGIS’ basic functionality. These additions come in the form of plugins. A list of all available QGIS plugins can be found here.
To add a plugin
And by now, most of you are aware of StackExchange, a network of Q&A communities. QGIS has its own StackExchange community, which you can find here
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
Website created and maintained by Noli Brazil