Geog 210 – Exercise 10 – QGIS

Introduction to QGIS, coordinate systems & projections


Return to Geog 210 page


Part 1 – Overview of QGIS

Adapted from Geospatial Innovation Facility (GIF) at UC Berkeley’s College of Natural Resources http://gif.berkeley.edu/

This exercise is designed to familiarize you with some basic concepts and capabilities of QGIS. You will explore the abilities of QGIS to visualize, navigate, manipulate, and analyze geographic datasets. You already know the GIS basis of the procedures used here.


Objectives
Dataset
Preliminary tasks
Task 1 – Adding Data
Task 2 – Symbology
Task 3 – Navigation
Task 4 – Working with Attribute Data
Task 5 – Basic Spatial Analysis
Task 6 – Exporting Data and Print Layouts


Objectives

In this exercise you will learn how to:

  • Create a map project
  • Add layers to your project
  • Display data to your specifications (e.g. colors, symbols, line weights)
  • Navigate the data using the zoom, pan, and full extent tools
  • Identify features and their attribute data
  • Query the map based on your criteria
  • Perform some geoprocessing operations
  • Create a map layout

To do this, we will use the data provided to select the best locations for community sponsored produce stands.

In our imagined scenario, the City of Berkeley, CA has assigned you the task of identifying lower income communities with limited access to fresh fruits and vegetables. The City would like to identify five civic buildings that are in close proximity to these neighborhoods and place weekly produce stands on their property. Therefore, your final product will be a map depicting the location of these potential sites and their service areas.


Dataset

The dataset contains several shapefiles from different sources. Note that a shapefile is composed of several files with the same name and different extensions. All these files of the same name must be in a folder together for the software to read them.

  • Berkeley_dem.tif – a raster “digital elevation model” displaying elevation for the City of Berkeley and surrounding areas.
  • Berkeley_shd.tif – a raster grid file displaying shaded relief based on elevation.
  • BerkeleyBlockGroups.shp – polygons containing demographic information for census block groups
  • BerkeleyLimits.shp – polygon of city boundary
  • County.shp – polygon of Alameda and Contra Costa Boundaries.
  • Fruit_Vegetable_and_FarmersMarkets.shp – shows point locations for fruit and vegetable markets, as well as Farmers Markets
  • PublicSites.shp – point locations of public buildings, institutions, and churches.

All layers are in the following coordinate reference system (CRS): Universal Transverse Mercator (UTM) Zone 10 North, North American Datum 1983 (NAD83)

If you choose to work on your own computer download the ex10.zip file from the Exercise 10 resources folder in Moodle and expand the zip file into a suitable folder BEFORE using the data.  If you’re working in the GPL just copy the \ex10 folder to your X:\ drive


Preliminary tasks

  1. Download the appropriate version (Mac or Windows) of the software from the official website. In the GPL we have installed version 3.34.12 ‘Prizren’ and these instructions are based on that version. Newer versions of the software might have light changes in the instructions.
  2. Download the appropriate dataset from Moodle or from the N:\ drive. The data is provided as a zip file. It’s important that you extract (unzip) that file into your working folder (X:\ex10 folder) if working in the GPL or into a suitable folder if working in your computer.

Please note that QGIS can work with data inside zip file giving you the impression that the data is available for editing/changing/saving/etc. It is NOT. Make sure to extract it first.

Task 1 – Adding Data

  1. Launch QGIS (Windows Start \ QGIS group \QGIS Desktop). If you get a prompt to load previous version data/settings, choose to start fresh. You should now have a new map window, similar to ArcGIS Pro: there’s a place for displaying data and a CP (here called Layers Pane).
Add Vector Layer button
  1. Look for the Open Data Source Manager button on the left of the second toolbar.
  1. In the dialog box (called Data Source Manager) make sure you’re in the Browser tab, on the left, and navigate to the working folder (X:\ex10)
  2. Highlight all shapefiles and TIF files (7 files in total). Select the files by holding the Ctrl or Shift keys.
  3. Right click on the selected files and choose “Add selected layers to project” (disregard/cancel any message about coordinate system for the raster images)
  4. Close the Data Source Manager window.

DON’T DO THIS:  you could have added individual Vector or Raster layers by using corresponding tabs (Raster and Vector tabs) in the Data Source Manager.

  1. In the Layers pane, check the boxes to the left of the layer name off and on. This makes the layer visible or not visible in the data frame. Click and drag the layers in the layers pane to rearrange their order in this way, from top to bottom:
  1. PublicSites
  2. Fruit_Vegetable_and_FarmersMarkets
  3. BerkeleyLimits
  4. BerkeleyBlockGroups
  5. County
  6. Berkeley_shd
  7. Berkeley_dem
Save Project button
  1. Click on the Save Project button.
  2. Save the map in your working folder (e.g. X:\ex10) and call it basic_map.qgz (or qgs, they’re equivalent; the “z” is a zipped version of the other; they both work the same way).

Save your work frequently throughout this project. Remember that a project file (.qgs or .qpz), like an ArcGIS project (.aprx), will save your display and layers, however it only points to the selected data files.  Data files are separate from the map (or project) file.


Task 2 – Symbology

  1. Change the BerkeleyLimits polygon to an outline by double clicking its name in the Layers pane (or right click\properties).
  2. Select the Symbology tab on the left
Simple fill
  1. Click on the “Simple fill” color sample.
  2. On the Fill style, pick “No Brush”.  
  3. Choose a dark blue for Stroke color.
  4. Increase the Stroke width to about 1 millimeter
  5. Click OK
  1. Right-click BerkeleyLimits and select Zoom to Layer.
  2. Get the properties of BerkeleyBlockGroups.
  1. Click on the Source tab. Change the “Layer Name” to Berkeley Census.
Single symbol drop-down arrow
  1. Click on the Symbology tab, click on Single symbol drop down arrow, and change it to Graduated.
  2. Make sure the color ramp is a monocolor ramp (any color, from light to darker)
  3. Select PERCAPITAI (Per Capita Income) in the Value field
  4. In the lower part of the Layer Properties window, set the number of classes to “6”, and Mode Equal Count (Quantile).
  5. Click OK, and you will see the census blocks vary in color according to Per Capita Income.
  1. Using the same steps as before, set the County layers’ Fill style to No Brush so that you can see the surrounding topography.
  2. To adjust the Style for the raster layers, access the layer properties menu for berkeley_dem
  1. In the Symbology tab set Band Rendering\Render type to Single band pseudocolor
  2. Choose a 2 or 3 color ramp (click the down arrow, not the color bar itself; experiment to something of your liking)
  3. Click the arrow next to Min/Max Value settings section and choose Mean +/- standard deviation to 1 (this setting is only to improve the contrast)
  4. Click Apply and close the dialog.
  1. Lastly, open the Layer Properties for Berkeley_shd. In the Symbology tab on the left change
    a. Render type to Singleband pseudocolor
    b. Color ramp to Grays
    c. Go to the Transparency tab on the left and set Global Opacity to 60%, which will create a 3D effect with the DEM. You can adjust transparency on any layer to maximize viewing. Also, try moving the semi-transparent Berkeley_shd layer above the polygon layers.
  1. Remember to save the project frequently.

Task 3 – Navigation

  1. Explore the data using some of the navigation tools in the Toolbar:
navigation tools
full extent button
  1. Click on the full extent button to see your entire dataset and experiment with the other navigation tools to see what they do. The mouse wheel is also very useful, try it.
  2. You can turn on and off the different toolbars by right clicking on an empty space in the toolbar. Familiarize yourself with the toolbars that are on (or off).

Task 4 – Working with Attribute Data

Every spatial unit, such as a polygon, point, or pixel may be assigned several values that are associated with relevant attributes. These values are stored in the database file (.dbf) and may be viewed in an attribute table or using the identify tool. This section explores attribute tables and some tools to query them.

Attribute Tables

Open Attribute Table.
  1. Right-click on Berkeley Census and select “Open Attribute Table.” Alternatively, click on the layer name in the Layers pane and push the table button on the toolbar.
  2. Explore the table. Each row corresponds to a spatial feature and each column represents an attribute.
  3. The total number of items is located on the top of the table (you should see 95 features)
  4. Click on the numbered grey box at the beginning of a row and the corresponding feature is highlighted in yellow on the map.
Zoom to selection button
  1. Click the Zoom to selection button, and the map zooms in to the selected feature. 
Unselect all button
  1. Click the Unselect all button on the top of the attribute table’s window to clear selection. Close the attribute table.

Selecting Features

Select Features button
  1. You can also select features directly on the map. Zoom to Berkeley Census then choose the Select Features button from the Selection Toolbar.
  2. Click inside of a polygon. Hold the Ctrl key to make multiple selections, or drag over a large area while holding the shift key. You will notice that features are highlighted both on the map and in the attribute table. Check the different tools for selection that you can try from this menu.
  3. Clear the selected values.

Alternatively, you can also select features based on their attribute values.

Select features by expression
  1. Click on Select by Expression tool, type the expression
    PERCAPITAI < 20000 in the left window, and push the Select Features button on the bottom of the dialog.

Notice the number of selected items (you should see 25) on top of the attribute table.

  1. The selected items can be exported/extracted to a new layer, by right clicking on the layer name in the Layers pane and “Export\Save selected features as”.  But we’ll look at this later.
  2. Another way to extract a set of selected items as a new data set is to apply a feature filter by using the Query Builder located in the layer’s properties.
  1. Clear the selection
  2. Go to the Berkeley Census Layer Properties\Source Tab, and push the Query Builder button on the lower right corner.
  3. Enter the expression PERCAPITAI < 20000 (this time you can pick the field name)
  4. Click OK and OK.
  5. Notice how the result is very different from before: Now it shows you only the 25 selected polygons.
  1. Now export the selected areas and create a new shapefile with only these areas: Right-click Berkeley Census in the Layer pane, and click Export\Save features as. Set the Format to ESRI Shapefile and browse to your working folder and name the new shapefile low_income_areas.shp, and accept the default projection. You can add this new file to your map. These are the low-income neighborhoods that the city wants to explore (verify that you have only 25).
  2. If you want to see all the census polygons in the original Census layer and remove the filter you applied (properties\source\ query builder)

Task 5 –Basic Spatial Analysis

In order to find the low-income areas that are being under-served by the current fruit/vegetable markets and Farmers Markets, we’ll make a buffer around them. The areas inside the buffer are already served by the current market, so we need to find the areas outside the buffers.

Buffers

  1. From the menu, choose Vector\Geoprocessing Tools\Buffer
  1. Select Fruit_Vegetable_and_FarmersMarkets as the input vector layer.
  2. Set a buffer distance of 1000 meters.
  3. In the field Buffered (this is the output), click the browse button (3 dots) and choose Save to File. Go to your working folder (X drive), choose shapefile (SHP) as type and enter MarketsBuffer.shp as file name.
  4. Leave all the other parameters as is and click Run.
  5. Notice the new layer (Buffered) in the Layers pane. Rename it to “Markets 1000 m buffer”.

Difference

To identify low-income areas that are greater than 1km from a fruit and vegetable or farmers market we’ll use the Difference function (This is equivalent to ERASE in ArcGIS) to get, out of the “low income areas”, the sections that are beyond 1km from existing markets.

  1. Choose Vector\Geoprocessing Tools\Difference
  1. Set low_income_areas as the Input layer, and Markets 1000 m buffer as the Overlay Layer, and Underserved_Areas.shp as the Difference layer.
  2. Where it says Difference click the browse button (3 dots) and choose Save to File. Go to your working folder (X drive), choose shapefile (SHP) as type and enter Underserved_Areas.shp as file name. Click Run.
  1. Turn off the buffer and low-income areas. Your new layer should show only low-income areas that are farther than 1km from markets (11 polygons).

Final selection

Since the city is asking you to choose the suitable public buildings for possible sites, we can’t let the GIS do all of the work. So, you’ll choose the final selection of five sites.

  1. Select five sites of your preference from the public building layer based on their service areas.
  1. Make sure that PublicSites and Underserved_Areas are both visible on your map (Turn off Fruit_Vegetable_and_FarmersMarket).
  2. Click on PublicSites layer in the Layers pane to highlight its name
selection tool
  1. Choose the Selection tool
  2. Use the Select feature tool and highlight five Public Sites that could represent good sites for community produce stands, based on their proximity to under-served areas. Hold the Ctrl key to select multiple features.
  1. Right click PublicSites in the table of contents and “Export\Save selected features as” to create a new file, in your working folder, of your five selected points. Name the file ProposedSites.shp.
  2. Hide the other public sites, and create 1km buffer around ProposedSites using the steps described in the previous buffer section.

Task 6 – Exporting Data and Print Layouts

Now you will export your data to other formats while emphasizing quality map design.

  1. Adjust your layers’ symbology AND labels to create a compelling map layout in your viewer BEFORE entering the QGIS print composer.
  1. Adjust the map so that you can see all of Berkely limits in your map view
  2. Make sure to show the proposed sites, the 1km buffers as empty circles (visible borders), the full census data (per capita income), the current farmer markets (different symbol/color from the proposed sites), county outline, and the two elevation rasters
  3. Rename the layers in the Layers Pane to show nice descriptive names.
  1. Enter the Print Composer by selecting, from the menu, Project\new Print layout.  Enter a name you like for the new layout.
  2. In the new window that opens, click the Add Item\Add Map tool from the menu, and drag a box over the blank workspace.
  3. Add a scale bar to the map using Add Item\Add scale bar and drag a box on the map.
  1. You can adjust the style and numbering by clicking on the bar and a pane should open on the right side (or right click the object and get properties)
  2. Change the units to kilometers
  3. Change the style to something you like
  1. Add a title to the map using the Add Item\Add label tool. You can adjust the text under the item tab (on the right pane; or item properties), and size and position by dragging the squares on the map. It can be edited on the right pane. Suggested title: Proposed Fruit and Vegetable Markets. Fix the appearance (font/size)
  2. Add a legend to the map by using the Add Item\Add legend tool and drag a box on the layout.
layout option pane
  1. Use the options in the pane on the right to adjust the legend to your liking. You can move items up and down and edit their names here.
  2. Uncheck the tick box “Auto update” then remove the legend items from the two rasters (they’re only there to make the map look good) and the vectors that are not being used using the red minus symbol ““ below the legend items.
  1. Add a North Arrow and your name.
  2. Spend some time adjusting the map (layer colors and textures). Make a good map composition.
  3. Export the map as PDF (Your_name_ex10.pdf) under the Layout menu. Save and close the project

Question 1.  Upload your map as PDF to Moodle.


Return to top

Return to Geog 210 page


Part 2: Defining coordinate systems & changing projections

Task 1 – Projection on the Fly

  1. Using QGIS make a new project and add the two layers in the folder \ex10\CRS (double click on each in the data source manager):
  1. Lake.tif – image of the lake
  2. GPS.shp – point vector layer of sampling sites in a lake in Wisconsin

You might get a message about “Select transformation for “layer” (either Lake or GPS). This message comes because you’re adding together two layers with different CRS. Disregard it for now (just Cancel).

  1. In the LP, double click GPS  to get its properties
coordinate reference system
  1. Click on Source tab and in the right panel, open Assigned Coordinate Reference System (CRS) and notice that it says EPSG: 4269 – NAD83. Click the icon to the right to learn about this CRS
  2. Study the new windows, especially the bottom one with the “Properties”

The coordinates of GPS are in Geographic Coordinate System (GCS), and the datum is the North American Datum 1983 (NAD 1983).

  1. Get the properties for Lake.tif

Question 2. What is the Datum for this raster? 
Question 3. What is the coordinate system?
Question 4. What is the projection?
Question 5. What are the linear units of this layer? 

The GPS layer is NOT “projected” (i.e. it’s in Geographic Coordinate System) and it’s registered in latitude-longitude (units DMS) with a datum NAD 1983, while the image Lake has a projected coordinate system (with linear units).

Despite the two layers having different coordinate systems, both layers are aligned with each other. This phenomenon is called projection on the fly. QGIS Pro displays both layers in the correct place on the map. Projection on the fly is valid if the layers are registered in any coordinate system and datum AND are specifically “defined” with the layer; Projection on the fly is great as we can quickly visualize our data but beware that some geospatial operations might not work properly. It’s always best to put all layers in the same coordinate system (datum, projection, units) before doing any Geoprocessing with them.

  1. Add the shapefile called Salinity.shp.
unknown CRS

You should get a question mark message next to the layer’s name in the LP. This means that this layer has an unknown coordinate system.

Also notice that the salinity layer might NOT show in the map.  Change the color of its points to something contrasting from the GPS points (if they have similar colors).

Depending on the order that you added the first two layers, Salinity might or might not fit initially in the map screen. 

  1. Click on the Question mark symbol and study the pane that opens.

It shows that Salinity.shp has missing spatial reference information. Therefore, Salinity.shp might not be displayed in the extent (map) of lake.tif and GPS.shp. This is because Salinity.shp is missing information about the datum (spatial information), i.e. the software doesn’t know where to place it.

  1. Using Windows Explorer (or Finder)  navigate to your working folder (e.g. \ex10) and notice that the shapefile GPS contains one file with the extension “.prj” and notice that Salinity does not contains this file (there is no Salinity.prj). 

The prj file contains the “projection information” that all GIS software need to place the data in their correct place. (The raster layer Lake.tif contains a file Lake.tfw that does some of this function).

  1. Double click both the GPS.prj file and the Lake.tfw to open them with any text editor installed in your computer (Notepad in the GPL) and you’ll be able to see their content. 

No need to understand them, but know that these are text files with projection information.  These are THE ONLY FILES that can be altered/deleted by humans if we know (or suspect) they’re wrong.  No other file should be manipulated with tools other than the GIS software.

Task 2 – Defining projection

The Salinity Layer includes total dissolved solid (TDS) information about the water in the lake. Therefore, it is supposed to be located inside the lake. The reason it is not located there is because it is missing projection information. In this step, you will assign a CRS to Salinity layer, so it will move automatically into its right location inside the lake.

The field technician that recorded the location of these sampling points in the lake, using a GPS, recorded that they were taken with the same info as GPS.shp (see instruction #2 above).

  1. Click, again the question mark next to Salinity.shp in the LP.

It should say that it has no “projection specification” and no more info.

Now let’s “explicitly define” the CRS of the layer so it’ll always be part of it (since we know what it is).

  1. Click (select) Salinity in the LP
  1. On the top menu click Layer\Set CRS of Layer
  2. Notice the heading of the new pane, it should say “Set CRS for Salinity:”
  3. In the section “Recently Used Coordinate…” you can see the CRS of GPS (EPSG:4269) and Lake (EPSG:4326) (Note that there’s also a section with Predefined CRS, you could search for your CRS there)
  4. Select the CRS of GPS (EPSG:4269) and click OK.

When finished, notice that Salinity now shows in the current window.  Check in the Layer properties that salinity.shp now has a defined CRS (the same as GPS).

  1. Go with the Windows Explorer or Finder to the working folder and notice that salinity.prj still does not have a .prj file (refresh the view in Explorer, press F5). That’s because the CRS definition is only part of the project, it’s not explicitly define in the shapefile, yet. To define the projection such that the prj file is part of the shapefile you’d need to “reproject” the layer (we’ll do this in the next task).

Note that this procedure didn’t create a new dataset (no output file). It didn’t change any of the coordinates. It only wrote a piece of code to tell the software what is the CURRENT projection. This tool is used when you know the projection for a layer is missing or incorrectly recorded. Obviously you should know what the correct projection/coordinate system is when you get some data or create one yourself.

Task 3 – Changing projections

As mentioned before some functions require that all layers involved have the same coordinate system. Imagine trying to clip a layer with units in degrees (Lat-Long) with a polygon with units in meters (UTM)!  This issue is approached differently by different software and by different functions within one software. So, to be safe, all layers that have to “interact”, like when we do geoprocessing operations, should have the same coordinate system.  Also, sometimes, it’s hard to define a buffer for a layer in DD!

You are now going to project Salinity from un-projected (and undefined) latitude – longitude onto Universal Transverse Mercator (UTM) zone 15 N.

The raster layer (lake.tif) and vector layer (GPS) in the LP have the same datum (NAD1983) but different coordinate systems. Lake is registered in UTM projection zone 15 N, and GPS is in geographic coordinates (GCS or Lat-long).

  1. Go to the menu Vector\Data Management Tools\Reproject Layer
  1. Input: Salinity [EPSG:4269]
  2. Target CRS: click the down arrow and select EPSG:26915 – NAD83 / UTM zone 15N (the CRS of Lake)
  3. Click Run

Notice that a new temporary layer “Reprojected” is placed in the LP.  Check its CRS

  1. To make the temporary layer permanent, right click on Reprojected and choose Export\Save Features As
  1. Format: ESRI Shapefile
  2. Filename:  Salinity_UTM (in your working folder X:\ex10\CRS\)

Go with Windows Explorer (or Finder) and notice that there is a new shapefile (Salinity-UTM) and this shapefile DOES contain a .prj file.

  1. Save your project in your working folder in case you need to comeback to it.

Return to top

Return to Geog 210 page


Part 3: Playing with projections in QGIS

There are hundreds of projections. Sometimes different maps of the same area look different, some are longer in N-S directions, others longer E-W, sometimes the map looks sort of tilted, etc. You need to get familiar with the characteristics of several projections and/or coordinate systems in order to use the most suitable one for your task. Now we’ll just play a little changing some projections. Your task is to search for the projection that makes the Earth look like a heart.

CRS info
  1. Start a new map and load the CRS\oceans.shp shapefile
  2. Click the button in the bottom right corner (the number might be different in your case)
  3. In the field of Predefined Coordinate Reference Systems, look under Projected Coordinate Systems
  1. Click on arrow next to Aitoff and select World_Aitoff
  2. Click the Apply button (to leave the dialog open) and move the dialog to the side to see your map
  3. Next try, under Albers Equal Area the one called Earth (2015) – Sphere / Ocentric / Albers Equal Area
  4. Continue testing different projections. Use only the ones that have “World” or “Earth” in their names.

Make sure to try conic, cylindrical, azimuthal, equal areas, and equidistant.

Love stamp

Question 6. What is the name of the projection of the world that looks like a heart?

In conclusion different coordinate systems (CRS) serve different purposes. By choosing the correct CRS, you ensure that features on your map are represented accurately. It is important to know the co-ordinate system of your data! If you need to transform your data to another system, you must know the “starting” system in order to change it. When all the data comes from one source, e.g. MassGIS, everything will have the same system. When get data comes from multiple sources, they might have different CRS and before doing any geoprocessing operations involving layers in difference CRS’s they must be transformed to a common CRS.


Return to top

Return to Geog 210 page