Skip to content

1.2.2.1 Getting Started with QGIS

David Kahler edited this page Feb 28, 2024 · 11 revisions

Download QGIS

QGIS

Download, Visualize, Edit Data in QGIS

This will walk you through a fairly general exercise to make a map of Pittsburgh, manipulate some data, and to visualize some data.

Basemap Data

Download Data

For visualization, it helps for people to recognize the setting you are showing. You should consider major features such as rivers, city/county/national boundaries, and even roads as potential landmarks when you make a map. For Pittsburgh, let's start with the county boundaries, rivers, and roads. There are multiple data sources, but let's start with the most simple (click on the "download" link to get a .zip file with the necessary data):

You are encouraged to explore the other data available at the Pennsylvania Spatial Data Access website. If you would like to add any of these data to your map, download the compressed (.zip) file, which contains the shapefile format (.shp and dependent files).

Load Data

Now, unzip the files and keep them in their newly created folders. It is easiest if you keep all of your GIS data in one spot so that you can reference it from within the GIS software. Keeping the dependent files all together in their native folders also helps you find your data. Although, it is best if you rename the folders something recognizable so that you can find the correct data. If you will work in multiple regions that do not have overlapping projects, you may wish to organize your files by place/project. Take time to figure this out now. GIS software does not copy data into the GIS project file, it keeps a record of where the file is on your computer to display; therefore, renaming or moving files after you have started your analysis will cause problems.

There are two ways to load data to QGIS. Most operating systems allow a drag-and-drop of the correct files (.shp, .kmz, .tiff); however, when learning, we will load data as the layer type as a way to illustrate the different data types. In general, layers (think maps, pictures, etc.) can be divided into vector or raster formats (we will read in a .csv later). A vector format is a list of instructions on how to draw the features. This format is common with technical drawing as it can always be redrawn with perfect, crisp lines (i.e., it does not become pixelated). A raster format is a table of values. This is most common in a photograph, where each pixel takes on a color value. These can become pixelated if they are enlarged too much. To start, we will just use vector data, which are stored as shapefiles (.shp); but also have referenced data in complementary data files that were unzipped in the same folder. To begin:

  • Select Layer -> Add Layer -> Add Vector Layer
  • Select the file by clicking on the ellipsis (...) button and navigate to the .shp file you wish to load
  • Click Add, then Close
  • Load all three shapefiles (either at once or repeat all steps for each file)

Visualize

Before we continue, let's play around with what we have. You'll notice that the waterbodies are only in Allegheny County because we are going to make a map of Allegheny County. For now, uncheck the box to the left of that layer to have it not appear on the map. Now we just have the counties and roads. Let's change how these look.

To change the colors:

  • Right-click on the County layer and select Properties (alternatively, you can double-click on it)
  • On the left navigation pane, select Symbology
  • From the drop-down on the top, select Categorized
  • Under Value, select COUNTY_N_1
  • Under Symbol, slide the transparency slider (under the color wheel) to about 50%
  • Under Color ramp, select Random colors (default)
  • Click Classify, then Apply

To add labels:

  • On the left navigation pane, select Labels
  • From the drop-down on the top, select Single Labels
  • Under Value, select COUNTY_NAM
  • On the left Label menu, select Buffer
  • Check the box for Draw text buffer
  • Click OK

At this point, you may notice something. The order of the layers on the layer pane (usually on the bottom left) is the order the layers are put on the map. This means that if you put a non-transparent layer on top of another, you will not be able to see the bottom layer(s). Let's get your data in order for this next part. Put your layers in the following order:

  • Top
  • Waterbodies
  • County
  • Roads
  • Bottom

Next, select some logical colors for the waterbodies (blue) and roads (dark gray). Try this one on your own. Now that you have those layers ready, let's look at the counties:

  • Right-click on the County layer and select Properties (alternatively, you can double-click on it)
  • On the left navigation pane, select Symbology
  • From the drop-down on the top, select Single Symbol (this will clear your categorization)
  • From the drop-down on the top, select Rule-based
  • Click on the plus icon
  • In the pop-up, click the sigma icon under Filter
  • In the pop-up, click on the arrow next to Fields and Values to expand the list
  • Double-click on COUNTY_NAM
  • While COUNTY_NAM is still selected, click on 10 samples on the right to get a sample of the values
  • On the left, it should now say: "COUNTY_NAM"
  • After the variable, click the = icon to enter an equals sign (or you can type it)
  • After =, double-click on ALLEGHENY on the right (from the 10 samples)
  • The expression should now read: "COUNTY_NAM" = 'ALLEGHENY'
  • Click OK
  • Click OK
  • Back at the properties window, click on the plus icon again
  • On the pop-up, select else
  • Click OK
  • Back at the properties window, right click on the color square to adjust the color for each element
    • For Allegheny, change the color to completely transparent
    • For ELSE, change the color to opaque white
  • Click OK
  • Back at the properties window, on the left-side navigation pane, select Labels
  • On the top drop-down, select No Labels
  • Click OK

Displaying Data

On top of the basemap, we should visualize our data. As an example, let's visualize the county elevated blood lead levels and the census data for percent poor housing units, which are both aligned by census tract.

Download Data

These data are available from the Western Pennsylvania Regional Data Center. Download the following data:

The top two are available as shapefiles and should be loaded into QGIS. The last dataset is in a .csv file; this contains no geographic information; the third dataset is the geographic information that can be used by the final data.

Visualization

Add the top two shapefiles just as you did for the previous shapefiles. Let's sort by color for the poor housing conditions:

  • Right-click on the Percent Poor Housing layer and select Properties (alternatively, you can double-click on it)
  • On the left navigation pane, select Symbology
  • From the drop-down on the top, select Graduated
  • Under Value, select PPoorCon
  • Under Color ramp, select a color ramp that makes sense to you
  • In the lower right, enter 6 Classes
  • In the Mode drop-down menu (under the large data window), select Natural Breaks (Jenks)
  • Click Classify, then OK

This provides a color-graduated map of the poor housing by census tract in Allegheny County. If we want to make a comparison to point data, we can add size variation, but we have another area that, if visualized the same way, would obscure the lower layer. Let's try something else: go to the Symbology options for the lead layer.

  • Select Graduated
  • Use the Value = Pct15_19 to sort
  • Assign a color ramp that you like
  • Under Symbol, click on the down arrow on the right and select Configure Symbol
  • You will get a menu with a tree with Fill and underneath, Simple Fill; click on Simple Fill
  • Under Fill style, select Diagonal X or similar symbol that is not solid

This is where you will see if you selected good, complementary colors to visualize your data. If not, or if you think you can do better, try again.

Align a CSV

A .csv file, or any flat data file, is basically a table arranged in a text file. The most common format is a comma-separated values (csv) file. The rows are arranged by row of the text file and the columns are separated by commas. QGIS can add in a csv file. For this purpose, there are two types of csv files: those with geographic data in columns and those without. For this example, we will consider a csv file without geographic data; this type of file will need to have references to some geographical code to match up to geographic data.

Analyzing Data

Download digital elevation model data from the USGS EarthExplorer website:

  • Sign in or create an account with EarthExplorer
  • Use the map to navigate to the Pittsburgh area
  • On the left, the second search criteria box gives you the option to click Use Map to select the area that currently is shown on the map
  • Zoom out on the map and adjust the corners if needed to encompass Allegheny County
  • Click on Data Sets at the bottom
  • On the following menu, expand Digital Elevation and then expand SRTM 1 Arc-Second Global
  • Click on Results at the bottom
  • Download the two DEM files that cover Allegheny County in .bil format (the others work too, but .bil is a smaller file)

Note, the Shuttle Radar Topography Mission (SRTM) is an amazing global high-resolution digital elevation model (DEM) that is a tremendous resource for the world that NASA has established.

Combine DEM

  • Ensure the two DEM files are loaded and appear as layers
  • Click on Raster -> Miscellaneous -> Merge
  • Click on the ellipses under Input layers
  • Select the two DEM layers
  • Click OK on the right (not Run)
  • Scroll down to Merged and click on the ellipses
  • Select Save file
  • Name a file (remember to sort your data files in logical folders); use *.tiff format
  • Click OK
  • On the main window, click Run

Elevation, contour lines, watershed analysis

Reproject your DEM to UTM (USGS UTM page):

  • Click on Raster -> Projections -> Warp (reproject)
  • Set the layer and initial coordinate reference system (CRS) based on the layer information
  • Set the target CRS to UTM: in Pittsburgh, use WGS 84 / UTM zone 17N; in South Africa, consider UTM Zones 35 or 36
  • Under Reprojected, select a destination file

We must next find any isolated depressions that could fool the computer into thinking that there should be a watershed that feeds a small basin, when in reality, it is just a depression that does not generate a meaningful watershed. To do this:

  • Go to Processing -> SAGA -> Terrain Analysis - Hydrology -> Fill sinks (wang & liu)
  • Select the reprojected DEM and new CRS
  • Keep the default Minimum slope of 0.01 degrees
  • It is recommended to save the Filled DEM
  • Run

Before the watersheds are identified, the channels must be identified. This is done by Strahler Order:

  • Go to Processing -> SAGA -> Terrain Analysis - Channels -> Strahler Order
  • Select the filled DEM
  • Run
  • Then, to isolate larger streams (remember, QGIS will find any possible channel), go to Raster -> Raster Calculator
  • Click on Strahler Order and enter in expression: >= 6, or a reasonable level
  • Save the result layer

In this example, we will analyze one watershed specifically. A watershed is typically defined by the downstream flow point; therefore, we need to find that point in UTM. Use that point in the following activity:

  • Go to Processing -> SAGA -> Terrain Analysis - Hydrology -> Upslope area
  • Enter the coordinates in UTM (m)
  • Select the filled DEM in Elevation
  • Select Method as Deterministic 8
  • You will save in the next step, so a temporary layer is acceptable
  • Run
  • Go to Raster -> Conversion -> *Polygonize (Raster to Vector)
  • Input the Upslope area and save the layer (make a new file to keep the shapefile dependent files together)

Elevation Profile

  • Start by installing the Profile tool by:
  1. click plugins at the top of the page
  2. select "manage and install plugins"
  3. Search "profile tool"
  4. Instal the profile tool
  • after the profile tool is installed click the profile tool and select the starting point
  • move to the ending point.
  • once the line has been created select the base map you want to use then click "add layer"
  • there will be three options: profile, table, settings.
  • the profile tool shows the graphed elevation and the table provides the data points
  • the table can be copied and added to excel

ESRI ArcGIS

Duquesne has a license for ArcGIS Pro with online access. If you require desktop access and don't have a Windows computer, DOVE Student has ArcGIS Pro and for ENVI 520: GIS, you may use an Azure virtual machine. You must get an invite code from your instructor. Follow the following steps:

Clone this wiki locally