Creating a IDW model in QGIS

From CUOSGwiki
Revision as of 04:18, 23 December 2021 by Pierceburch (talk | contribs)
Jump to navigationJump to search

What to expect from this Tutorial

Going through this tutorial using ' Quantum' GIS ([1]): You will be gain the following skills.

  • Importing CSV file
  • creating interpolated raster surfaces using IDW
  • symbolizing the interpolated raster surfaces
  • clipping raster surfaces with base map polygons
  • exporting the raster surfaces as a finished map.

Purpose

The purpose of this tutorial is to expand your ability to run important analysis tools such as Interpolation and Image analysis (IDW) [[2]], using several proprietary tools [3], with the end goal of creating a finished IDW interpolation map. The difficulty level for this tutorial is an entry-level QGIS user, But it is assumed that the user has some experience with other GIS systems Such as ArcPro or ArcMap. I chose to create this tutorial to try and bridge the gap between this software and Esri’s products. Making it easier to learn how to use the software and carry out the functions that the user is already familiar with.

  • This tutorial will be incorporating some screen-shots for each step to show the path I took to create all the layers that are in the finished product

Introduction

The purpose of this tutorial is to learn how to use the proprietary tools in an open-source platform. I decided to do this in QGIS as the software is often looked at as the main competitor to Esri as the design and application are similar to that of ArcPro and ArcMap. This tutorial looks to try and bridge the gap between this software and Esri’s products, to make it easier to learn how to use the software and carry out the functions that the user is already familiar with. Although the software looks similar differences between QGIS and Esri’s products which are often taken as the industry standard. This all ties into making this tutorial practical and accessible for all users picking up this software for the first time, or just wanting to expand their knowledge. This was chosen to help show off the strength of open-source software in a practical way encouraging those to use it more often.

open-source

open-source ([4]) is a term that refers to having accessible, free and redistributable programs available to the public. This allows for individuals to work on the code together in order to create a model that encourages open collaboration and develops code together.

GIS

In our case, a license subscription to Esri can be extremely expensive to have just one account leading to a lot of overhead costs for full teams. This is why having open-source and freely available software is vital for users to know to bring down costs where possible. To look at GIS programs available for free download, you can visit the [5] page to look at all the projects currently being worked on by the community.

Downloading QGIS (3.22)

for this tutorial, you will need to have QGIS installed [[6]] on your desktop or laptop. at the time of creating this tutorial, QGIS 3.22 is the most recent stable version and the version all of this tutorial is being done in. Once you have selected the version you wish to download based on your operating system, follow the guide that is installed in the package. With QGIS 3.22 now installed on your computer and a proper path for accessing the application on your hard drive, you are now able to start the tutorial!


This tutorial was created as a result of the final project given out in the GEOM-4008 GIS course at Carleton University. If you wish to look at other tutorials created by other students, this can be found at [[7]]

Data

The data I selected for this tutorial goes along with the theme of keeping everything open source and using publicly available data from the Canadian government. To ensure the longevity of this data we will be using monthly climate summaries from Stat CAN as it is very extensive and easily accessible data for all provinces and territories in Canada. This in-depth look at provincial weather will be the best and easily malleable data set to use for our project. For this case, we will be looking at Alberta's average mean temperature. This will give us a good well-distributed data set that we will be able to use to create an IDW model and help us guess the values of areas that we do not know.

Downloding the data

  1. Go to [[8]] and scroll to the bottom of the page
  2. being by clicking the year 2 years before your current date; (as of today it's Decmeber 2021 so I would use December 2019 etc)
  3. Select your area of interest (for this assessment I used Alberta as it has the most climate stations in the country)
  4. ensure that you are downloading the CVS data and click the download button when ready.
  5. Be sure to also download the Legend(txt) file as it will allow you to see what all the data is meant to represent
  6. We now need our boundary file, to get this go to [[9]] and download the ArcShape file and click the provinces under "Cartographic Boundary File"
  7. this will bring you to a second screen that says "Archived – gpr_000b11a_e.zip (ZIP version, 40,968.0 kb)" click this and download this for the project

Editing the data

With this data having so many variables we need to edit it to make it easier to work with:

  1. Open your CVS file using Excel and make sure that you select "separated by a comma" to format the file correctly.
  2. beginning with the variable to include in the set, use your legend(txt) file to locate the mean temperature and delete all other variables not dealing with location or identification
  3. right click on the "Clim_ID" column to select the entire row
  4. under the home tab of Exel click the sort/filter drop-down menu and select largest to smallest.
  5. You should see a bunch of stations that are all formatted to the left of the cell and will contain letters unlike the rest of the data set. Select all these rows and delete them from your file (do not worry, they are not needed and can create some issues when loading it into QGIS)
  6. Once you have done this save your data and you are ready to bring it into QGIS
    1. note: If you are having issues with bringing the data into QGIS make sure that all of your climate ID's are correctly formatted as this can stop the data from being able to be read by QGSI


Tutorial

Loading CSV File and Provincial Boundary File

  • Launch QGIS (version 3.22 or newer) and ensure that you have downloaded the correct data sets. and create a new project file
  1. at the top of your toolbar, click the plugin tab and click the "manage and install plugins" item.
  2. In the "all" tab, search for the "QuickMapServices" plugin and install it to QGIS. once this is done restart QGIS
  3. once you are back into a new project layer, click the web tab at the top and go to the QuickMapServices dropdown and select oms standard. (this should add in a base map to your project)
Screen Shot 2021-12-22 at 10.32.11 PM.png
  1. we will now add in our 2 layers starting with the weather stations. by clicking on the layer tab at the top of the page go to the "add layer" tab and scroll to the "Delimited Text layer"
  2. in the new window, click the 3 dots at the top right corner of the screen (you will be finding the CVS file that we edited earlier) once you have found it make sure that the "Comma" and "tab" boxes are checked off in the "custom delimiters" file format
  3. in the Geometry definition option set your x field to "Long" and your y field to "Lat" so that QGIS knows how to read your coordinates
Screen Shot 2021-12-22 at 10.49.12 PM.png
  1. click on the layer tab at the top of the page go to the "add layer" tab and scroll to the "add Vector layer" tab
  2. in the new window, click the 3 dots at the top right corner of the screen (you will be finding the boundary file we downloaded) in the package you downloaded click the file with the .shp end to it and add it to your project
    1. once it is loaded in right-click on it and select "Open attribute table"
    2. once open click the pencil at the top of the window. then select all layers besides Alberta and click the " delete selected feature" tap on the toolbar you clicked the pencil on
    3. once this is complete correctly you should only have the Alberta boundary file on your project layer (and the weather stations)
  3. The next step will be to create a permeate layer for your weather station points. to do this right-click on the layer and click export "save feature as"
  4. Give this a name and click the 3 dots next to your name for the layer. create a space where you will be saving all your file layers ( I would recommend creating a new folder to keep everything in to keep all your paths the same for the project) once all of this is done ti should look something like this
Screen Shot 2021-12-22 at 11.23.32 PM.png


Interpolating data to create a Raster Surface layer

  1. Begin by clicking the processing tab at the top of the application window and selecting the

"toolbox" tab. This should bring up a menu on the left side of the application with a search bar at the top of its menu.

  1. in the search bar type in "IDW Interpolation". there will be several options that come up but for our tutorial, we will be using the proprietary tool that QGIS officially backs and created for its software. Once you have located it double click the tool to open the IDW window
  2. In the new window, where it says "Vector layer" select the name of the weather station layer we created earlier. Once this is done it will ask for the interpolation attribute that you will be interpolating, select the "Tm" attribute as this is what we will be working with
  3. right bellow interpolation attribute drop down there is a plus button, click this and the layer will be added the table below. In this table select the "points" tab under the type dropdown.
  4. below this we have the Distance coefficient P set at a default of 2, I would recommend increasing this to 5 to account for the northern and western portion of Alberta since these areas have very little station data available compared to southern Alberta. this will add more weight to pixel values and their distance to other stations.
  5. below this there is the extent tab with a dropdown on the right side of the terminal, click this and go to calculate from layer, this will bring up the other layers currently on your map. Select your boundary file as the extent
  6. if everything is done correctly it should look like the picture shown below. if it does click the "Run" button at the bottom of the window.
Screen Shot 2021-12-23 at 12.16.29 AM.png


Clipping Interpolation Surface to create a final raster layer

  • This portion of the tutorial will focus on creating a masked layer for the raster layer we just created in order to fit within our boundary file.
  1. at the top of the application there is a raster tab, click this and scroll to the "extraction" tab and select the "clip raster by mask layer"
Screen Shot 2021-12-23 at 12.25.12 AM.png
  1. At the top of the window select your interpolated layer as the "input layer". you want to mask it to the shape of Alberta so choose the boundary file as your "mask layer"
  2. Ensure that both layers are using the same projection and then click run.
Screen Shot 2021-12-23 at 12.39.28 AM.png
  • You will notice that these layers are only temporary and if you were to close the application right now the layer would not save to combat this we need to export the layer as its own GeoTIFF file so that we can share your data later.
  1. to do this right-click on the layer and click export "save feature as"
  2. Make sure the format is GeoTIFF and click the 3 dots next to the file name. in the folder you created earlier give this layer a name like AB Weather IDW. once all of this is done it should look something like the figure on the left
Screen Shot 2021-12-23 at 12.48.13 AM.png
  • to finish this layer off we will be changing the symbology as the tones of gray are hard to grasp with a dataset like this. to change this right-click on the new layer and select the "properties" button at the bottom of the pop-up window.
  • at the top of this window it says "render type" click that menu and select "single-band pseudocolour". this will allow you to select a colour ramp different from black and white select something that makes sense for your map, of this example I have used the "plasma" ramp to show the difference between the warmest temperatures and the coldest.
Screen Shot 2021-12-23 at 1.08.23 AM.png
  • Once this has been completed and looks complete save your project by clicking the project tab and selecting "save as" this will bring you to the folder you created earlier. Name your project Alberta Weather IDW map and click "save".
  • once this is completed the analysis portion of the tutorial is over and you successfully ran an interpolation on open source software!


Exporting the Final Maps

  • Under the ‘Project’ tab, select “New Print Composer’.

Image41.png


  • Assign a ‘print composer tittle’ that will be used for the new print composer (For example: ‘Spline Map’). Under the ‘Layout’ tab, you can add a number of map elements to the print composer including the actual map, a legend, scale bars, etc., depending on the nature and purpose of the final map. For this tutorial, experiment by adding the spline interpolation map, map title (under ‘add label’), a legend and scale bar. A few tips: Make sure you zoom to the layer extent of the spline interpolation map first before adding it as a map to the print composer, text editing for the ‘label’ is done in a text editing box on the right hand side of the print composer window. There is a wide variety of graphics editing tools within this print composer, so feel free to explore and play with them before exporting the final map.


Image40.png











  • An example final output map is shown below. The last step of this tutorial will be exporting the map.
Image43.png









  • There are a number of formats available to export the final map as, which including: JPEG file, PDF or as an SVG file. For the purpose of this tutorial, we will export the map as an SVG file, so that it can be loaded into an open source graphics editor such as Inkscape for final touch-ups if needed. To export the map, click on the ‘composer’ tab and select the ‘Export as SVG’ tab.

Image44.png


  • Assign a file name to the exported SVG file, and click save. And that concludes this tutorial.

Conclusion

In conclusion, this tutorial aimed to show the user how to import point data into QGIS, run interpolations on the point data, clip and symbolize the data and export the interpolated data as a finished map. I hope this tutorial provided adequate instructions on how to download the software and data, and to perform the various tasks needed to create IDW and Thin Plate Spline interpolation maps. Unfortunately, I did not have the time to create a tutorial on kriging using an open-source GIS program, but this is certainly still something I would like to do in the future. Please feel free to comment on anything in this tutorial that is poorly explained or does not make any sense, and feel free to contact me by email if you have further questions.

Resources