Skip to content

Instantly share code, notes, and snippets.

@kgjenkins
Last active September 11, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgjenkins/7eca97d49d077e589d81d5b936e016f8 to your computer and use it in GitHub Desktop.
Save kgjenkins/7eca97d49d077e589d81d5b936e016f8 to your computer and use it in GitHub Desktop.
ARCH 5115 - QGIS Workshop, Day 1

ARCH 5115 - QGIS Workshop, Day 1

Workshop 2020-09-09 by Keith Jenkins, GIS Librarian at Mann Library

For help after this workshop, contact me at kgj2@cornell.edu
Or set up a Zoom appointment at https://guides.library.cornell.edu/gis/help

Data for this workshop is located in the "QGIS-workshops" folder on Box

Some GIS Concepts

GIS stands for Geographic Information System (or Science)

"GIS data" refers to data with a spatial component -- it can be mapped!

QGIS is one of several popular GIS programs for mapping and spatial analysis. It is free, open-source desktop software that runs on Windows, Mac, and Linux. QGIS is created by developers around the world, supported by municipal and national governments, corporations, user groups, and individual users. Discussions about new features, bug fixes, and future directions happen on e-mail lists and the project's GitHub organization.

Questions about how to use QGIS are typically asked and answered on GIS StackExchange. If you google for QGIS questions, there is a good chance you'll end up finding the answer already there, so search before asking a new question.

Vector = points, lines, polygons

Raster = pixels (images, but also data)

Data = Geometry + Attributes

Vector data does not usually contain any information about how to style the display of the data.

Styles are added in a map project. The same data could be styled in different ways in different maps, or even in the same map!

The QGIS project file .qgz contains your styles and pointers to the data, but does not include the data itself. I recommend keeping everything within a containing folder (there can be subfolders) that you can zip up or save to a device or the cloud.

CRS = Coordinate Reference System

Ideally, CRS details are quietly handled behind the scenes, so we barely even need to think about it.

But in the real world, you'll eventually run into CRS puzzles, and CRS becomes even more important when doing distance- or area-based analysis.

  • EPSG:4326 = WGS 84 -- "common longitude/latitude"
  • EPSG:4269 = NAD83 -- longitude/latitude, similar to WGS 84, but only defined for North America
  • EPSG:3857 = WGS 84 / Pseudo-Mercator -- also called "Web Mercator", uses false "meters" (only true at equator)
  • EPSG:3452 = NAD83 / Louisiana South (ftUS)
  • EPSG:26915 = NAD83 / UTM zone 15N (meters)

Parish boundaries

"Parishes" in Louisiana are what other states call "counties". The parishes.gpkg file was extracted from a 2019 nationwide county boundary shapefile that was downloaded from https://www.census.gov/cgi-bin/geo/shapefiles/

QGIS was used to select just the Louisiana polygons and export them to a geopackage. GeoPackage is a modern, open geospatial data format that is supported by most GIS software.

Load the parish boundaries:

  • Look in the "parishes" folder and drag the parishes.gpkg file onto the QGIS window

Change the layer style by opening the Layer Styling panel – colorful paintbrush icon at top left of the Layers panel

  • Change the color
  • Click "Simple fill" to change other properties, like stroke color and width

Get information about a parish:

  • Click "Identify Features" tool, select the pollingplaces layer, then click a polygon

View information about all the parishes as a table:

  • Right-click layer in Layers pane > Open Attribute Table
  • Click the "NAME" column header to sort by that column

The table and map are linked, so select Orleans from the table (by clicking the row number) to see it highlighted on the map. There is a toolbar button to "Deselect features from all layers".

Add labels by clicking the label tab (yellow "abc") in the styling panel

  • Single Labels, value = NAME
  • 9 tabs of options!
  • 1st tab (text) - font, size, color
  • 2nd tab (formatting) - wrap lines to 12 characters
  • 8th tab (placement) - Horizontal

To find out what CRS (coordinate reference system) is being used:

  • Right-click > Properties... Source tab

Save your project!

Save "mymap.qgz" to the folder that also contains your data -- for example, within the "QGIS-workshops" 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.

Road centerlines

The City of New Orleans has a dataset of road centerlines -- one line per road, regardless of how many lanes it has. This data is in a shapefile format, which is 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/

  • Look in the "roads" folder, and drag the .shp file onto QGIS

Explore the data a bit (identify tool, attribute table), and notice the contents of the "ROADCLASS" column. We can use those values to control the layer style.

  • At the top of the layer styling panel, change "Single symbol" to "Categorized"
  • Set Value = "ROADCLASS", then click the "Classify" button towards the bottom of the panel

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.

  • Change all the road colors to black
  • Double-click the "Freeway" symbol to edit it -- change the width to 1.5mm
  • Change the "Major Arterial" width to 0.75mm

Try turning on labels for the roads and zooming in and out a bit.

  • PRO-TIP: Use Ctrl-scroll to zoom more slowly with more control

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...

  • Turn off your road labels, since we'll use a basemap instead.

Basemaps via QuickMapServices

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.

  • Plugins menu > Manage and Install Plugins...
  • Scroll down, or search all plugins for "quickmap" (you don’t need to type the whole name)
  • Select the QuickMapServices plugin
  • Click the "Install plugin" button (it installs in seconds)
  • Click "Close"

When you first install QuickMapServices, you'll want to get the full set of basemap definitions.

  • Web menu > QuickMapServices > Settings
  • "More services" tab > "Get contributed pack"

To add the Google Hybrid basemap, which combines aerial photos with placename labels:

  • Web menu > QuickMapServices > Google > Google Hybrid
  • Turn off your roads and parishes in order to see the basemap

Most basemaps are in a different projection (CRS) called Pseudo- or Web-Mercator, EPSG:3857. QGIS is reprojecting it to match the CRS of our parishes, which can cause some pixelation, making the labels hard to read. If you zoom out, you'll notice that the US looks stretched out.

To avoid the pixelization and the stretched shapes, we can set our map to use the basemap CRS:

  • Right-click the Google layer > Set CRS > Set Project CRS from Layer
  • Right-click the Google layer > Zoom to Native Resolution (100%)

Turn the roads layer back on, and explore how well it aligns with the imagery.

Turn on the parish layer, and adjust the style to work better with the basemap:

  • Click "Simple fill", then set fill style = No Brush
  • Set the stroke color to orange
  • Switch to the label tab and set the label color to orange
  • 3rd tab (buffer) - Draw text buffer, 1.5mm black

As we add more data, it will help to use a plainer basemap:

  • Web menu > QuickMapServices > Stamen > Stamen Toner Lite
  • Uncheck the Google Hybrid layer to hide it
  • Adjust the parish style as needed (white buffer, for example)

The Stamen Toner Lite layer is very light, so we can add our own roads on top if we want to emphasize the New Orleans road network.

  • In the roads style panel, adjust Layer Rendering > Opacity to control the visual weight of the roads

COVID-19 Testing Sites

As an example of point data, we will look at a dataset of COVID-19 Testing Sites. The Louisiana Department of Health website lists the public testing sites available in each parish. However, as is often the case with infomation on the web, this list is not readily accessible as data that can be used to make a map. The information is displayed in a dynamic widget where the user must first click on a small map, and then there is no way to directly download the data for the 25 testing sites in Orleans parish. And even if it could be downloaded, it only contains a street address, which would have to be geocoded -- QGIS has tools for this -- in order to get the longitude/latitude coordinates necessary to display the sites as points on a map.

Fortunately, a team of volunteers from the GISCorps, a program organized the URISA (Urban and Regional Information Systems Association), has collected and aggregated COVID-19 data from across the country, and offers a nationwide dataset of testing sites.

  • Look in the "covid-test-sites" folder, and drag the .shp file onto QGIS
  • Explore the data a bit (identify tool, attribute table)
  • Adjust the display style as you see fit -- maybe try "Categorized" by "status" or "drive_thro"

Extracting a data subset

Notice that this dataset covers the whole United States, including Alaska and Pacific island territories. We can use this dataset to extract just the points for the area around New Orleans, and save them to a new file.

  • Zoom back in to New Orleans so that you can see all of the city with plenty of margin.
  • Click the "Select Features by area or single click" tool in the toolbar (the 1st of three yellowing icons in a row)
  • Click the "Testing_Locations" layer name, then drag a rectangle around the points surrounding New Orleans (better to select too many than not enough)

Those points should appear yellow to show that they have been selected.

  • Right-click the "Testing_Locations" layer name > Export > Save Selected Features As...
  • Format = GeoPackage
  • Click the "..." to set the file location and name -- call it "covidsites.gpkg"
  • The layer name will automatically copy the filename (before the .gpkg extension) -- best practice is to only use letters, numbers, and underscores, although QGIS is fairly forgiving, unlike some other GIS software.
  • Leave the CRS as is (EPSG:4326 - WGS 84)
  • Click "OK"

The exported file will automatically be added to the map. You may now remove the original testing sites layer:

  • Right-click "Testing_Locations" > Remove

Inverted Polygons to mask surrounding areas

One last trick, to set the focus of our map on the City of New Orleans, will be to mask the areas outside the single Orleans parish. The "inverted polygon" option will apply a style to the outside (rather than the inside) of a polygon.

  • Right-click the parishes layer > Filter...
  • Enter the following expression: "NAME" = 'Orleans'
  • In the styling panel, change "Single symbol" to "Inverted polygons"
  • Click "Simple fill" and set the fill style to "Solid"
  • Set the Fill color and Stroke color to black
  • Click "Fill" to get to the option for setting the feature opacity, setting it around 65%

Exporting your map to an image file

To export the current map view to an image file:

  • Project menu > Import/Export > Export Map to Image...
  • Update the extent or leave as is
  • Increase the resolution (try 300dpi)
  • Save as a .png file

Exporting your map to a PDF 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.

  • Project menu > Import/Export > Export Map to PDF...
  • Check the settings, especially the resolution if your map includes raster layers, including basemaps

Exporting data layers to a DXF file (for CAD software)

Architects often want to export GIS layers for use in a CAD program like Rhino or AutoCAD. Since DXF is a vector format, only vector layers can be exported -- sorry, no basemaps! When exporting to CAD, be sure to set an appropriate CRS for the exported data, which means a CRS based on meters or feet -- not degrees longitude/latitude.

  • Project menu > Import/Export > Export Project to DXF...
  • Click the "..." button to specify where to save the .dxf file
  • Be sure to select an appropriate CRS! QGIS will reproject all your layers to the chosen CRS.

Coming next... on QGIS Workshop Day 2

  • elevation data - pseudocolor, hillshades, and contours
  • levees
  • imagery webservices
  • georeferencing scanned maps
  • demographic data
  • transit routes
  • oil and gas wells
  • current covid-19 cases
  • other data sources

Data Sources

Parish boundaries were extracted from US Census shapefiles, which contain many other types of boundaries as well.

The City of New Orleans has an Open Data Portal with many geospatial layers, including:

There are even more datasets in the portal, so be sure to search there for more.

Cemeteries in New Orleans have been mapped pretty well in OpenStreetMap (OSM), a collaborative map of the world that is the most complete map of streets in the world, with better coverage than even Google and Bing. OSM contains much more than streets, and there are many ways to download OSM data, such as this link to an Overpass query:

Oil Refinery locations are available as part of a collection of Homeland Infrastructure Foundation-Level Data:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment