In this guide you will learn how to make a map in QGIS. The objectives of the guide are as follows
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
Geographic information systems (GIS) are used in a wide range of academic and applied fields. Simply put, GIS allows you to combine tabular data (e.g. spreadsheet sheet) with geographic boundaries (e.g. maps). 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, QGIS is very similar, except it has less functionality but is free.
You can download QGIS at their website. I generally recommend working with the most recent version of QGIS available or the most recent Long Term Release, which is designed to be maintained with bug-fixes and such for the next three release cycles. Long term releases might not have the most newest features found in the most recent version, but focus is broader stability across time. At the time of writing, the most recent version is 3.2.2; the long-term release is 2.18.9.
This tutorial is based on 3.2.2 for Windows. Other than installation instructions, there should be no noticeable difference between Mac and PC versions
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. Download the installer under Standalone installers from OSGeo4W packages.
Mac users: 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, but it’s actually a very common process.
Go to the Additional Labs -> QGIS Canvas folder and download the zip file qgis onto your Desktop or a convenient place on your hard drive that you can readily access. Unzip the folder. The folder will contain shapfiles and csv files that we will be using in the lab.
Open up QGIS. You should see an interface similar to Figure 2.
The components of the interface are as follows
Let’s bring in a shapefile. You can do this a number of ways.
Let’s use the Data Source Manager approach. We want to bring in a shapefile showing Census tracts in Sacramento county. As we discussed in Lecture, tracts are areal data, also known as Vector data. From the Data Source Manager window
We got a shapefile into QGIS. Hooray! But, we need to map something. Let’s bring in some data to map. This will come in as a .csv
. Go back to the Data Source Manager and follow the steps below.
We now want to attach (merge) the csv data to the shapefile. To do this, follow the steps below.
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, right click on Sacramento_County_Tracts from the Layers panel and select Open Attribute Table. The table should pop up and contain 317 rows corresponding to the 317 tracts we have displayed on the map screen. Scroll all the way right - you should see the variables we added from tracts_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. To do so, follow the steps below.
You should see Sacramento_County_Tracts_Dems pop up in your Layers panel. Because we only need this shapefile moving forward, remove tracts_demographics and Sacramento_Country_Tracts by right clicking on each from the Layers panel and selecting Remove Layer.
Let’s map percent poverty at the tract level for the county of Sacramento. The first thing to do is to symbolize our map based on percent poverty.
You should get something that looks like Figure 15.
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.
From the Main Menu go to Project and click on New Print Layout. A dialog box will pop up asking you for a title - type in “Percent Poverty by Census Tract in Sacramento County”
You should see a screen that looks like Figure 17 pop up. This is known as 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 18.
The map of Sacramento county maps should pop up. With the map now displayed, you can
The scale of the map shown in the Map Layout will match what is shown in the main 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 that using the tool or just type a scale in directly to the scale box. I do the latter by typing in 1:300000 as such . The scale in the Map Layout window will not update - you will have to do it manually. Go back to the Map Layout window. Click anywhere on your map. On the bottom right panel, click on Item Properties, scroll down midway, and click on the button Set to map canvas extent. You should see Sacramento county fills up the page a little more.
1. Click on Add Item from the Main Menu of the Map Layout window
2. Click on Add Legend.
3. The same cross cursor will pop up, which means you’ll need to click, hold and drag to the place where you want to place the legend.
If you want to customize the legend, click on the legend, check the bottom right panel and click on Item Properties. A window named Legend should be there. You can customize how the legend looks by playing around with the properties. For example, we can give the legend a more descriptive name by double clicking on Sacramento_County_Tracts_Dems under Legend items
This should bring up a little dialog box. Under Item text, give the legend a more descriptive name, such as “Percent Poverty”. We can also change the title “Legend” by simply clicking in the white text box next to Title under Main Properties and typing a title name. 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. So far, here’s what our 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, my arrow looks like
How did I make the arrow look like this? Under Main properties, I selected Middle in the Placement pull down menu to center the arrow. I then selected black in the pull down menu next to Fill color under SVG Parameters to make the arrow black.
You can’t have a map without a descriptive title.
As with all features, you can customize as you see fit. Under Appearance, I clicked on the Center radio button under Horizontal alignment and the Middle radio button under Vertical alignment. This will center the title text. I clicked on the pull down menu directly under Appearance and increased the font size to 25. My map now looks like Figure 23.
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 two ways.
A base layer provides geographical context to a region of interest. For example, a base layer might help viewers orient themselves to a specific county by displaying the surrounding counties. Let’s add a base layer of California census tracts to the map.
Select the pop down menu next to Color. From there, move the black circle towards a light pinkish color.
Click OK - the symbol should now no longer be white but look something like * You’ll notice that a symbol for California_Tracts pops up in the legend of your map. Let’s eliminate that because it’s not necessary. To do this, turn off Auto update under Legend items by unchecking the box. Then click on the California_Tracts and then click on . California_Tracts should disappear from the legend. You should get a map that looks like Figure 26.
The function of a basemap is to provide background detail necessary to orient the location of the map. QGIS does not have basemaps preloaded. You’ll need to rely on a QGIS plugin to get a basemap. QGIS plugins are user created functions and applications - remember that QGIS is open software, so if you are a programmer, you can create and add to QGIS’ basic functionality by making your own QGIS tools.
To add a plugin
You should see some new buttons pop up in your toolbars. Select and you can select basemaps from a variety of different sources. OSM is Open Street Maps, a free crowd sourced editable map. Select OSM and select standard. The OSM basemap should pop up both in the Map and Layout views. Customize the map as you see fit. I ended up with the map shown in Figure 27
Ultimately, you’ll want to share this map with others. You usually do that 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 into one of these formats
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 their original location. 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.