Difference between revisions of "Automating Vector and Raster Workflows using the Graphical Modeler in QGIS"

From CUOSGwiki
Jump to navigationJump to search
Line 117: Line 117:
 
*With the model built and double checked we can go ahead and save the model. Enter a model name and a group name, then select the red-underlined button third from the left to save the model in an appropriate location. Lastly, select the circled button in order to run the model.
 
*With the model built and double checked we can go ahead and save the model. Enter a model name and a group name, then select the red-underlined button third from the left to save the model in an appropriate location. Lastly, select the circled button in order to run the model.
 
[[File:14_SaveRun.png]]
 
[[File:14_SaveRun.png]]
  +
  +
*Once the run button is clicked, you will be asked the set the layers to match the input vector parametres.
  +
  +
*Lastly, save an output and make sure the box is checked to allow for the output file to open once the model is finished running.
  +
[[File:15_SetLayers.png]]
   
 
== Output ==
 
== Output ==

Revision as of 03:49, 21 December 2015

Disclaimer

Please note that this tutorial was created as a term project for the Carleton University class GEOM4008 - Advanced Topics in Geographic Information Systems. The tools used below are just a some of many that can be found within QGIS and outputs may heavily vary depending on the inputs. The results should not be used as conclusive findings for others work.

Introduction

The objective of this tutorial is to provide an in-depth walk through of automating two workflows in the QGIS Graphical Modeler. The first is a simple workflow using sample vector data that covers geoprocessing tools such as; buffer, clip and merge. It will also demonstrate how to perform a field calculation within a model. The second workflow is more complicated and works with a sample Digital Elevation Model (DEM). The workflow covers the various steps required to determine the watershed basins within an area of interest. The different algorithms covered in this tutorial are; fill sinks, catchment area, channel network, watershed basins and vectorising grid classes. These algorithms are native to SAGA GIS, but through QGIS's advanced interface processing toolbox, they as well as GRASS GIS algorithms are accessible. This tutorial provides a highly explanatory and easy walk through for individuals with varying levels of GIS knowledge. The purpose is to aid those looking for a quicker, more efficient way of performing long workflows without the use of expensive GIS software.

Software

As mentioned above, the software that will be used for this tutorial is Quantum GIS, otherwise known as QGIS. It was chosen for two reasons; first, it is one of the most powerful GIS FOSS (Free and Open-Source Software) with a very user friendly interface; second, it has a very intuitive Graphical Modeler that has access to many different algorithms from GDAL, GRASS, ORFEO Toolbox, QGIS and SAGA. Along with being very powerful and free, it is also available for all platforms (Windows, Mac OS X, Linux, BSD, and Android).

In order to follow along with this tutorial, the first step is to download QGIS:

http://www.qgis.org/en/site/forusers/index.html

From this website, you will find a link to download the software to the appropriate platform and documentation for getting started.

Data

The data for these tutorial originates from two websites. The first set of data required for the vector workflow tutorial is available from the City of Ottawa Open Data website. The data sets required are:

Roads - http://data.ottawa.ca/dataset/roads

Proposed Roads - http://data.ottawa.ca/dataset/roads-proposed

Water bodies - http://data.ottawa.ca/dataset/water

NOTE: Make sure to select the download link associated with the SHP format.

For the raster workflow tutorial, the only required data is a DEM of whatever area you are interested in. For this tutorial, the DEM will be accessed through Scholars GeoPortal which houses huge amounts of geospatial data that is freely available to those studying within one of the 21 schools that fall within the Ontario Council of University Libraries (OCUL). The DEM chosen for from Scholars Geoportal comes from the retired, Ministry of Natural Resources, Provincial Digital Elevation Model Dataset - Version 2.0.0. The DEM covers a portion of Eastern Algonquin Park, located around the Barron Canyon (20km x 13km) and has a cell resolution of 10m.

Tutorial for Automating a Vector Workflow

With QGIS open, the first thing to do is to add the vector data.

Adding Vector Data

There are 2 methods for adding vector data into QGIS. The first method is to simply just drag-and-drop the vector layer file you would like to add. The second method involves using the menus and is highlighted below.

  • Along the top toolbar, select Layer --> Add Layer --> Add Vector Layer

1 AddLayer.png

  • After selecting Add Vector Layer, a dialog box will pop-up and this is where you will browse for the Vector Layer you are looking to add

1 AddLayerDialog.png

  • For the tutorial, this will be done 3 times in order to add our roads, proposed roads and our water bodies. Below you will find what QGIS looks like with all 3 layers added.

1 DataAdded.png

Opening the Graphical Modeler

  • Before we begin creating the model we need to change the processing toolbox interface from Simple --> Advanced. This option can be located at the bottom of the processing toolbox.

2 ToolBox Advanced.png

  • Without changing it to advanced, inside the Graphical Modeler, you would only have the ability to use the simple interface algorithms
  • To open the Graphical Modeler, in the top toolbar go to Processing --> Graphical Modeler. The window should look like the one below.

2 GM.png

Creating the Input Parameters

  • In the figure above, you'll notice many types of input parameters with "+" signs next to them. In order to add in a vector layer parameter, double click on that option.
  • In the dialog box that pops up, give the layer a name unique name, change the shape type to match the data type (point, line or polygon) and set required to Yes.

3 InsertParameter.png

  • Do this 2 more times for the other 2 vector layers.
  • After adding all 3, the Graphical Modeler window will look like this:

3 GMwLayers.png

Creating the Model

Buffer

  • Creating the model is actually relatively simple. Search for the desired tool, then double click on it and set the parameters.

8 FindTool.png 9 Buffer.png.

  • Make sure to set a description to differentiate it from the others, as well, set the proper input layer.
  • Specifically for the Buffer above, I decided on a 25.0m buffer of the roads and unless you have plenty of time, set dissolve to NO.
  • You'll notice no output vector was specified and that is because it is not required until the last tool in the model or whenever an output is desired.
  • Do this for both of the Roads files with the same parameters other than the input layer.

Merge

  • With both of the road layers buffered, we will now merge them into one road layer (you can also merge first and then buffer, whatever tickles your fancy). Refer to the image below for which tool to use and how to set the parameters.

10 Merge.png

Clip

  • Now that the road buffers have been merged, we will use the QGIS vector overlay clip tool too determine where there is overlap between the road buffers and the water bodies.

11 Clip.png

  • The clip can be performed either way (i.e. the input layer and the clip layer can be switched if you please).

Field Calculator

  • In order for us to determine the amount of area where a 25m road buffer would overlap the water bodies, we will perform a field calculation. Refer to the image below to the input layer, field type, length and precision and for the formula

IMPORTANT NOTE:

  • As this is the last step in the model, we now are required to specify an output layer, so do not forget to do that (this can be seen as the blue rectangle that appears under the Field Calculator dialog box.

12 FieldCalc.png

Final Look

  • With the model now built, I recommend taking this time to go back through the tools (selecting the pencil in the bottom right hand corner of each processes) to make sure all the inputs and parameters are set correctly.
  • The model should look a little something like the one found below.

13 ModelMade.png

Save & Run

  • With the model built and double checked we can go ahead and save the model. Enter a model name and a group name, then select the red-underlined button third from the left to save the model in an appropriate location. Lastly, select the circled button in order to run the model.

14 SaveRun.png

  • Once the run button is clicked, you will be asked the set the layers to match the input vector parametres.
  • Lastly, save an output and make sure the box is checked to allow for the output file to open once the model is finished running.

15 SetLayers.png

Output

Tutorial for Automating a Raster Workflow

Step1

Step2

Step3

etc

Conclusion

Helpful Links & References