Workshop tutorial created by Keith Jenkins email@example.com, Mann Library, Cornell University (revised 2023-09-25)
This workshop will cover basic tasks using QGIS: loading data, changing the styles used to display the data on a map, installing plugins, using processing tools to do basic analysis, and exporting a finished map image.
The Windows computers in Mann Library already have QGIS installed, but if you would like to use your own computer, please install QGIS on your computer before the workshop. QGIS is a free and open source geographic information system that runs on Windows, Mac, and Linux. In most cases, you can download and install QGIS on your own computer in under 10 minutes. (For Windows, we recommend using the latest version of the "Standalone Installer".)
Download and unzip the data files for this workshop:
We will explore several common types of GIS data, using the following example datasets:
|DATA TYPE||FILENAME||CRS (Coordinate Reference System)|
|points||fire_stations.csv||EPSG:4236 = WGS 84|
|lines||streets.shp||EPSG:26918 = NAD83 / UTM zone 18N (meters)|
|polygons||towns.gpkg||EPSG:4269 = NAD83 (latitude/longitude)|
|raster||elevation.tif||EPSG:26718 = NAD27 / UTM zone 18N (meters)|
Point data is often found in a tabular format, such as an Excel file or a CSV file. To use a data table in QGIS, it is usually best to first export the table into a CSV file. CSV stands for "Comma-Separated Values", and is the format most commonly used to transfer tabular data between different programs. Whenever a table includes X and Y coordinates – such as longitude and latitude – we can use that information to display each row in the table as a point on a map.
Load the fire station data:
datafolder and open the
You should see a constellation of dots floating in space. Don't worry – we'll soon be adding more layers to make a more useful map.
Let's change the layer style by opening the Layer Styling panel - colorful paintbrush icon at top left of the Layers panel
Get information about a point:
You make better use of limited screen space, you may want to re-dock the "Identify Results" panel – click on the panel title, drag it towards the middle of the screen and then back towards the right and drop it when the blue highlighted area takes up the full right side of the window. Then you can switch between the "Layer Styling" and the "Identify Results" by using the tabs at the bottom.
View information about all the fire stations as a table:
The table and map are linked.
Add labels by clicking the label tab (yellow "abc") in the styling panel
Notice how the labels change as you zoom in and out of the map. A mouse with a scroll wheel is highly recommended for mapping!
Save "mymap.qgz" to the folder that also contains your data – for example, within the "qgis-workshop" folder. That way, you can zip up or move the containing folder around while keeping your map and data intact. The .qgz project file contains your map styles and pointers to your data files, but not the data itself. If you move or rename your data files, your project file won't know where to find them.
Points, lines, and polygons are different types of "vector" data, which can be stored in many different file formats. Shapefiles are probably the most common geospatial data format found on the Internet, but the shapefile format dates from the early 1990s, which is why there are multiple component files (.shp, .dbf, .shx, .prj, and sometimes others). To add a shapefile to QGIS, we just need to select the .shp file and QGIS will take care of the rest. Shapefiles also have other quirks, mostly notably a 10-character limit for attribute names. Learn more at http://switchfromshapefile.org/
Lines are a type of vector data that is often used to depict linear features like rivers and streets. Street datasets sometimes called centerlines, since the streets are often represented by one line per road, regardless of how many lanes there are. We can add this data using the Data Source Manager, but we can also add it just by dragging-and-dropping the file onto QGIS.
streets.shpfile onto QGIS
QGIS may prompt you with a question about coordinate system transformations. It's usually okay to accept the default, but sometimes there may be a more accurate transformation specific to the area you are mapping.
Our map is still using the CRS from the first layer we loaded, which uses latitude/longitude degrees, which are not the same distance east-west and north-south, so the map may look a bit stretched out. Let's use the coordinate system of our roads layer, which is based on meters:
Explore the data a bit (identify tool, attribute table), and notice the contents of the "SHIELD" column. We can use those values to control the layer style.
Random colors are assigned to each of the values, which is not really what we want. You can shift-click to select all the values, then right-click to change the color for all the values at once.
Try turning on labels for the streets layer and zooming in and out a bit.
There are many options that can be configured to improve the appearance of the labels, but it can require a lot of work and even manual adjustments to make it look really good, so…
Basemaps are web-based map images designed by professional cartographers who have already done the hard work of aggregating different data layers and customizing styles and labels to work at different zoom levels. Basemaps are usually global in scope, although there are some that only focus on certain regions. They can be used to add context to your map, or just to help confirm that your data is correctly aligned. The QuickMapServices plugin makes this easy, but we need to install it first.
When you first install QuickMapServices, you'll want to get the full set of basemap definitions.
To add the Google Hybrid basemap, which combines aerial photos with placename labels:
Most basemaps are in a projection (CRS) called Pseudo- or Web-Mercator, EPSG:3857. When using a basemap, it's usually best to set our map to use the basemap CRS in order to avoid the pixelization of stretched imagery:
Turn the streets layer back on, and zoom in to an intersection to see how well it aligns with the imagery.
Turn on the fire station layer, and adjust the label style to improved legibility against the basemap:
Since the Google Hybrid layer often has the clutter of unwanted points that distract from our fire station points, it will help to use a plainer basemap:
Polygons are yet another type of "vector" data. This time, we'll explore a geopackage of towns (county subdivisions) in New York state. GeoPackage is a modern geospatial file format designed to overcome the limitations of shapefiles. Learn more at http://www.geopackage.org/
Load the town boundaries:
Update the town layer style:
Add town labels:
Save your project!
QGIS has hundreds of analysis tools in the Processing Toolbox. As an example, suppose we want to know how many miles of roadway each town has within its borders.
First, we are going to select just those towns that are in Tompkins County (the towns layer covers all of NY, but we only need Tompkins)
Next, open the processing toolbox
When the process completes, we should have a new layer called "Line length". Notice that this layer has a computer chip icon (which also looks like an insect) next to it – this indicates that it is a temporary layer held in memory, not saved to disk.
Save these temporary results to a geopackage:
We can copy the style from original "towns" layer to the new "townroads" layer:
We can convert the total road lengths to miles, and add it to our map labels:
LENGTH / 1609.34
"NAME" || '\n' || round("LENGTH" / 1609.34) || ' miles'
Note that the
|| operator is used to join text strings. Watch out for the quotes!
Double quotes are used around column names, and single quotes around text.
The '\n' represents a newline character.
Raster data is fundamentally different than vector data. Raster data is made up of pixels, which might represent colors (aerial photographs or satellite imagery), or numeric values (elevation, temperature, precipitation, etc.) We will explore an example of elevation data, where each pixel contains a number representing the elevation about sea level. This dataset doesn't include any colors, but we will visualize the pixel values in multiple ways.
Load the elevation data:
For maximum visibility of all layers, we would usually want to move a raster layer to beneath the vector layers. But for now, just turn off the other layers by unchecking their boxes in the Layers list.
The default style of a raster layer is a simple grayscale gradient from black to white. Let's apply a color gradient:
Try using the "Identify Features" tool to check the elevation at different points on the map. Are the heights in feet or meters?
Let's create a hillshaded version of this layer. In the past, you had to create a separate hillshade output file, but now you can simply create and adjust a hillshade in real time using the styling panel.
The "Value Tool" plugin will let us see the values of all the visible raster layers as we move the cursor across the map, which is much quicker than using the "Identify Features" tool.
Install the plugin:
Once installed, the "Value Tool" icon will appear in your toolbars. It looks like a green version of the "Identify Features" icon. After clicking, you may need to enable it on the panel that appears. Try it with the elevation raster.
There are many other plugins available for handling special data formats, managing tabular data, performing analysis, creating time-based animations, and interfacing with other programs. Some of our other favorite plugins include:
To export the current map view to an image file:
Exporting to PDF is useful if you are going to print your map, or if you want to do further work in a program like Inkscape or Adobe Illustrator. The PDF will keep separate layers for each data layer. Vector layers will remain vectors, and raster layers will remain raster.
It is also possible to create a more detailed map layout, with things like a title, text boxes, a north star, and legend. We won't go into the details here, but the general process is: