course mod topic first name date completed
DAT-201 Wk. 4 QGIS and Map Layouts
module learning objectives
  • TR.201.DS.8.F - Maps - Spatial Joins
  • TR.201.DS.8.D - Maps - Creating study areas
  • TR.201.DS.8.G - Maps - Layouts & printing

Some More QGIS Practice

Note: we're doing all of this in class, together. I wrote it out in case that's easier for you, or you want to remind yourself how to do some of this later.

Layouts

Sharing Maps Outside of QGIS

We will want to communicate with people who don't have QGIS, sometimes. Creating print map layouts will help us do so effectively.

For this exercise you can choose any of the maps you've created in class or for homework. I will use the map showing percentage of households without internet that we created last session, but you are not constrained by my choices, here.
  1. Open the project you want to create a map of.
  2. Zoom in/out until the area you want to map is taking up most of the map panel.
  3. Go to Project -> New Print Layer, and give your print layout a title. This title will be the default filename for your map when you export it to PDF (or JPG, but use PDF). It will also be how you pull it back up when you want to re-export.
  4. To add your map to your layout, go to Add Item -> Add Map.
    • When you mouse over the page on the screen, crosshairs will appear.
    • Hold down the left mouse button and drag to select how much of your page your map will take up. You'll be able to resize and reposition as needed, later.
  5. When you have your map on your page, go ahead and save.
  6. Now let's add a legend using the Add Item menu.
    • Consider changing its title to something more helpful (or at least "Legend") under Item Properties -> Title. If you use a long title, you can add a character to wrap on. (On one map I wrapped on the character "x" and used the title "Households xWithout Internet")
    • Under Legend Items, you have the option to turn layers/groups on and off by right-clicking and choosing "Hidden." (QGIS may require you to turn off "Auto Update" first.)
    • You can also relabel your layers by clicking the pencil-and-paper button below the Legend Items box.
  7. If you'd like to add a compass rose, you can go to Add Item -> Add Picture, and the ellipsis to choose a file should take you to a pre-loaded list of pictures. (If your QGIS, like my QGIS, fails to do this by default, and if you're on Windows, you can find them in C:\Program Files\QGIS [number]\apps\qgis\svg.) You can try several out, to see which you like.
  8. A title, other commentary, citations for data sources, and any other text labels you might like to add are under Add Item -> Add Label. You can use HTML markup to style your text--remember to check the "Render as HTML" box.
  9. Once you've added items to your heart's content and you're ready to make a sharable map, go to Layout -> Export as PDF.
If you want to make an overview map, the directions are very similar; only, you'll add your zoomed-in area as a map, and then you'll zoom back out and add a second map. Do yourself a favor, and lock your first map before you do this.
  1. With the second map selected, in the Item Properties tab, open the Overviews dropdown.
  2. Click the plus mark to add an overview. (You can double-click and name it something more descriptive than "Overview 1," if you choose to do so.)
  3. Assuming the wide area map is Map 2 and the zoomed-in area map is Map 1, you'll choose Map 1 as your Map frame.
  4. Choose a Frame Style that makes sense. (Simple fill in red is often a default, but if you're doing this on a map that's colored in shades of red, you might choose a different color/style.)
  5. Blending Mode might look familiar if you've used Photoshop in the past. Try a few different ones and see what looks best. I seem to be mostly drawn to Normal and Burn.

Drawing your own polygons


We're going to draw a couple of Canadian provinces (because they're easier than most states, and we can all use a brush up on Canadian geography).
  1. Start a new project.
  2. Add OpenStreetMap as a layer.
  3. Create a new shapefile layer. (Layer -> Create Layer -> New Shapefile Layer)
    • Save it as "provinces.shp" in the directory you're working in tonight.
    • Set it as a polygon geometry type.
    • Add fields "id" (whole number) and "name" (text).
    • Canada is kind of far north. There might be a better projection to use, but for now, let's go with the project's CRS -- EPSG 3857, Pseudo-Mercator.
  4. Make sure you have the Digitizing Toolbar and Snapping Toolbar turned on (View -> Toolbars, and make sure both are checked)
  5. In the Digitizing Toolbar, enable editing (pencil) and choose the Add Polygon Feature tool (looks like a golf course or a green swimming pool with a little orange star under it)
  6. Trace Saskatchewan. Right-click when you're finished, and a little table will pop up, asking you to enter an id (1) and the name of the province.
  7. Now, before we start Alberta, do yourself a favor, and turn on the Enable Snapping tool (looks like a horseshoe or magnet)
  8. Now you can snap to the top left corner of Saskatchewan, to start drawing Alberta. It'll also snap to the bottom left corner when you finish.

Bonus content (not going over in class) - Fixing Broken Shapefiles


Let's see if the WPRDC's copy of the Neighborhoods shapefiles will work for us. We're going to If it doesn't work, we'll try to do the repair. In slightly less detail than week 3's descriptions, here's what the fix looks like:
  1. Open the Processing Toolbox and find "check validity" under Vector Geometry
  2. Click the little wrench ("Configure," if you're fancy)
  3. The rule you want to add is "Neighborhoods_ must not have invalid geometries"
  4. Click the checkmark to have it show you any neighborhoods with invalid geometries. (Unchecking "Show Errors" will make the red area go away.)
  5. Note the neighborhood ID, and select it from the Attribute Table
  6. Open the Toolbox (the gear beside Field Calculator), and search for "fix"
  7. Open "Fix Geometries," make sure the input layer is Neighborhoods_, make sure the "selected features only" box is checked, and give it a directory and new filename to save the fixed neighborhood to.
  8. Now we're going to remove the broken neighborhood from our layer. Maybe you want to save your project first.
  9. Go into the Attribute Table of Neighborhoods_. Probably, the neighborhood with the geometry issues is still selected. (There's a "move selection to top" button!)
  10. Click the pencil to put the table in Edit Mode, and then (making sure only the one row is highlighted) click the trash can to remove this attribute. Click the pencil again to exit edit mode, and save the changes.
  11. Now we have to put our fixed neighborhood back into its parent layer. Go to Vector -> Data Management Tools -> Merge Vector Layers, and choose Neighborhoods_ and Fixed geometries as your input layers. Give a location for the saved file to go (obviously, I called mine "fixed_neighborhoods" when I did this in the past).

Homework

You have a draft question for your project. (We are coming up with those tonight, if you don't have one already.) You have some serious QGIS mapping skills. So you'll want to make progress on your project this week, to have the whole thing ready by week 7.

Pieces we expect to see in your presentation for the mapping project:

Pieces you'll need to turn in digitally: