Beginner's Guide to TINs, DEMs and Contours Using QGIS
Introduction and Intent
There are two purposes of this tutorial, the first being to introduce new Geographic Information Systems (GIS) users to the uses of Triangular Irregular Networks (TINs), Digital Elevation Models (DEMs) and traditional cartographic contour lines. The second objective of this tutorial is to show the processes that users can follow to create, manipulate and use these three datatypes within the QGIS open source software. The three aforementioned datatypes are related in one key way, they are all different means of representing elevation data. They differ in the ways they accomplish this and the types of data they use. These distinctions are discussed in the Vector vs Raster section of this tutorial.
QGIS
QGIS is an open source, free Geographic Information System that lets users display and modify geometric datasets. This means that data that incorporates any sort of geographic positioning, such as incorporating coordinate points into a spread sheet, can be used to create data that exists in a 2 dimensional space. This is a very powerful tool for any user that wants to communicate spatial information to a client, peer or superior. Skills in the use of GISs like QGIS increase the user’s ability to disseminate information easily and are in demand in fields ranging from transport, mineral exploration and exploitation, construction and far more.
Downloading QGIS
For the purposes of this tutorial, you will have to download a copy of QGIS from the download portal here (https://qgis.org/en/site/forusers/download.html). This tutorial was updated using QGIS 4.2.3. QGIS is available free of charge from the official QGIS website. Users should download the current version appropriate for their operating system. The exact appearance of menus may vary slightly between QGIS releases.
Once the above link is clicked, a download will commence. After it has been completed, a download tool will launch. Simply follow the tools instructions to complete the download of QGIS 4.2.3.
QGIS – Getting Started
After installation, launch QGIS Desktop from the Windows Start menu or the shortcut created during installation. Once QGIS opens, create a new blank project.
QGIS – Overview
Once QGIS launches, you’ll be met with the user interface (UI). In order to get you somewhat acquainted with the interface before we start delving into TINs, DEMs and contours we’ll briefly describe the five main components that make up the UI. These components are highlighted in Figure 2 through the use of coloured blocks. All of the following colour coded sections refer to Figure 2.
Menu Bar (Highlighted Purple): Provides access to QGIS’s main commands and tools. Menus include Project, Edit, View, Layer, Vector, Raster, Processing, and Plugins.
Toolbars (Highlighted Red): Comprise the icons below the main menu. These play a similar role to the main menu, except that each toolbar focuses on a specific task with related functions and uses icons instead of words. The available toolbars can be customized depending on the tools required for a project.
Browser Panel (Highlighted Yellow): Allows users to navigate folders and access spatial data stored on their computer or through connected data sources. Files can often be added to a project by locating them in the Browser Panel and dragging them into the Map Canvas or Layers Panel.
Layers Panel (Highlighted Green): an area where the user can view the layers they have open in QGIS. Any files you load into QGIS will appear here. You can turn on/off all layers, modify their display order and look at their properties in this panel.
Map Canvas / Main Display Area (Highlighted Blue): This is simply a display panel. Any spatial information will appear here so long as the layer is turned on.
Processing Toolbox (Not displayed in screenshot): The Processing Toolbox contains many of the spatial analysis tools available in QGIS. It can be opened by selecting "Processing" then "Toolbox" from the Menu Bar. In this tutorial, the Processing Toolbox will be used to access tools such as TIN interpolation.
Elevation Display Datatypes
Now that we have a basic idea of what QGIS is, why it’s important and how to get it running we’ll start manipulating data to create our three types of elevation display data. It’s important to understand these three display types as they all use data types that are ubiquitous in GIS and are the most common way of displaying elevation in GIS.
TINs (Triangular Irregular Networks)
What are TINs?
TINs are a way of displaying the elevation of a surface. They use vector point data which have x, y and z values associated with them. The x and y locate the 2 dimensional location of the point, while the z gives the elevation of the point. Z data is important because without it the TIN has no real meaning. The points supplied are connected to their neighbours by triangles giving the process its namesake. Using a TIN means that detail within the connecting triangles may be lost, however, they can represent elevation with relatively few points.
Data Import
In order to create a TIN, we need to import a point vector layer that contains z values. Each point should contain horizontal coordinates defining its location and an attribute containing elevation values. The subsequent examples refer to this elevation field when configuring the TIN Interpolation tool. The original elevation dataset associated with this tutorial is no longer available from the CUOSGWiki. The data used in this tutorial is a point vector layer containing elevation values, with an attribute field such as ZVAL. The file used in this tutorial is called “Spot_Heights.shp”. Make sure all files being used are unzipped and accessible by QGIS. In the end, your folder should look something like this (Figure 4) and it should be located in a directory similar to this (C:\Users\YourUserName\Documents\Tutorial).
Now that the elevation file is on your computer, we can import it into QGIS. To do this, go to the “Manage Layers Toolbar” and click the “Add Vector Layer” icon
. This will open the “Add Vector Layer” tool. (Figure 5)
Ensure that under “Source type” the inputs are set to “File” and “System” as shown above. Once this is complete left click on the browse button and navigate to the area of the “Carleton Elevation” folder were all the SHPs, SHXs and DBFs are stored. Once there, double click on the .shp. (Figure 6)
Once this is complete, simply click “Open” in the “Add Vector Layer” tool. The elevation points should open in the “Main Canvas” and the title of the layer should be in the “Layers Panel”. It should look something like this, though the colour may vary. (Figure 7)
If there is no image displaying in the “Main Canvas” go to the “Layers Panel” and ensure that the layer is appearing there. If it is, right click on it and hit “Zoom to Layer”. This should bring you to the points if they are outside of our extent. (Figure 8)
If the layer is not there, simply repeat the previous steps in this section. Now that your data is imported into QGIS we can create a TIN.
Alternatively, users can simply drag the .shp into QGIS from Windows Explorer.
Creating a TIN
We can create a Delaunay Triangulation and a raster representation of elevation based on this Delaunay Triangulation. Delaunay Triangulation will connect nearest neighbor points to each other, however this will not represent elevation in 2 dimensions. Delaunay triangulation shows the triangle connectivity, while TIN Interpolation uses that triangular structure to interpolate elevation values. This is why we have to rely on the derived raster layer when working in 2 dimensions.
Delaunay Triangulation
First, we will create our Delaunay Triangles in order to see how the process works. We will do this by going to the “Vector” selection in the main menu and navigating to Vector/Geometry Tools/Delaunay Triangulation. (Figure 9)
Once clicked, the “Delaunay Triangulation” tool will launch. Ensure that the layer we added earlier is selected in the input layer. (Figure 10)
Once this is complete, simply click the “Run” button. The processing may take a few minutes and QGIS may become unresponsive. Avoid clicking in QGIS during processing. A second layer should appear on top of the “Spot_Heights” layer in the “Layers Panel” and “Main Canvas” (Blue). Notice that the new layer named “Delaunay Triangulation” consists of triangles connecting our point to their neighboring points. (Figure 11)
Delaunay triangulation determines which elevation samples are connected to form the triangular structure used by a TIN. The polygon output is useful for visualizing the triangulation but an interpolated elevation surface will be created in the next step.
DEMs (Digital Elevation Model)
What are DEMs?
A DEM is a digital representation of the earth’s surface. There are typically two types of DEMs, a DTM (Digital Terrain Model) and a DSM (Digital Surface Model). A DTM is a representation a ground surface that does not include vegetation or buildings, while a DSM includes everything captured in the elevation data. The data you’ve downloaded is a surface model that has had a vegetation removal algorithm run on it. This means we will be creating a DTM. A DEM uses elevation data to create a raster output. In order to add readable elevation to our triangles, we’re going to create a DTM.
DEM - Raster Creation
Now we need to use the set the proper parameters that will create a raster representation of the point vector layer using Delaunay Triangulation. To open the tool, simply go to the “Processing” option in the menu bar and follow the path Processing/Toolbox/Interpolation/TIN interpolation. This will open the TIN interpolation tool. (Figure 12)
In the tool under “Input layer(s)”, ensure that “Vector Layer” is set to “Spot_Heights” because this is the layer with elevation points. Set “Interpolation attribute” to “ZVAL” because this is the column in our layer attributes that has the elevation data. Once this is done, click the green plus button. This should make the layer and attribute appear in the table below. (Figure 13)
Under the “Output” section of the tool ensure that “Interpolation method” is set to “Linear” and maintain the size of the "Columns” and "Rows" at “300”. The “Pixel size X” and Y determine the size of the pixels in the raster. Larger datasets may require larger cells to reduce system stress. We have a relatively small dataset, so we will set our cell size to “200”. The extents of the interpolation are automatically set to those of the inputted dataset(s), meaning we can leave them at their default. It’s worth noting that if you only want to interpret a certain area, you can zoom to the desired extent and click “set to current extent”. Finally, place the “Output file” in the Tutorial folder under the name “RasterInt”.
Once these inputs are complete, click “Run”. Once processing completes, a third layer will enter the “Layer Panel” and be displayed in the “Main Canvas”. The low points will be displayed as black and the high as white on a grey scale. By looking at the “Layers Panel”, we can see the lowest and highest points(min and max). (53m and 286m in Figure 15)
By looking at the layer, we can make out certain features. The data is of elevation points taken from Ottawa/Gatineau, Canada. We can see the lowlands of the city area, the lowest (black) area representing the river and the high (white) areas which are the hills of Gatineau. (Figure 16)
If we go into the “Layers Panel” and by clicking and dragging our “Delaunay triangulation” layer above our “RasterInt” layer we can see the impact of the Delaunay Triangulation. Double click on the “Delaunay triangulation” to open the attribute table. One the “Layer property” tool is open, navigate to the “Style” category. Double click on “Simple fill” in the upper left. This should open the “Symbol layer type” options. Under “Fill” set the type to transparent fill. (Figure 17)
Now in the “Main Canvas” we can see the “RasterInt” layer under the “Delaunay triangulation” layer. You can see that the patterns of elevation in the “RasterInt” match closely to those in “Delaunay triangulation” because they both use the same process. (Figure 18)
This is the easiest and most useful way of creating a 2D TIN within QGIS. The raster used to represent elevation makes the output a raster instead of vector as a pure 3D TIN would be.
Contours
What are Contours?
Contours are the traditional way of representing elevation in a paper map. The contour is a line that represents a continuous elevation. The proximity of a contour to its neighbours indicates steepness of slope. Two contours close together represents a steep slope, while contours far apart indicates a gentle slope. If an area has very few contours, it is likely a flat area. Creating contours is easy once we have a raster layer. Though contours are used less now than in the past and do not represent continuous elevation as well as DEMs or TINs, they still do a good job of getting elevation and slope across to an audience. They are simple to understand and can be easier for individuals whose last contact with mapping techniques was in high school. Many maps are still being digitized from physical maps with contours, so understanding them in QGIS is important.
Creating Contours
First, make sure that “RasterInt” is still in the “Layers Panel” because we need a raster layer to create the contours. Go to “Raster” in the main menu and follow the path Raster/Extraction/Contour. (Figure 19)
This will open the “Contour” tool. Ensure that “Input file (raster)” is set to the raster layer “RasterInt”. Set the “Output value” to the “Tutorial” folder and name it “ContourOtt”. The “Interval between contour lines” determines how far the distance between each contour will be. This is up to you, but bear in mind that too many contours can clutter a map and two few can make discerning slope difficult. The default of “10” is usually a good starting point. Check the “Attribute name” box and set it to “Elev”. This will be the field where the generated contour elevation is stored. Finally, hit the “OK” button. (Figure 20)
A layer named “ContourOtt contour Line” will be created. We can see that the lines are closest together in the hills near Gatineau and farthest apart in the lowlands near Ottawa. (Figure 21)
Conclusion
By completing this tutorial, you have learned how to navigate the main QGIS interface, use the Processing Toolbox, import elevation point data, create a Delaunay triangulation, perform TIN interpolation, and generate contour lines.
