 Hello, this is Hans van de Kwas, Senior Lecturer at IHG Delft Institute for Water Education. In this video I'm going to show how to delineate a catchment using PCRuster and GDAL commands, so completely command line-based. We are using the same dataset as used in the book QGIS for hydrological applications, which can be ordered at LocatePress. In a previous video I've shown how to set up the environment for using PCRuster and Python and GDAL. We are going to use that environment in this demonstration. The first step is to activate the PCRuster environment. In a previous video I've showed how to create that environment. We use COMDA, activate PCRuster. Now we'll go to the folder where we have the files, and the first thing that we need to do is make a mosaic of the TIFF files that we see here. In the folder we see a shapefile with a bounding box that helps us to delineate a little bit the area where the catchment is. We see four TIFF files that have been previously downloaded from the Earth Explorer website. We are going to use a GDAL function for that. Go to GDAL.org, you can find your programs, and there is GDAL build VRT. With GDAL build VRT we can make a virtual dataset, in this case that is good enough, because we're going to later crop it and we project it so we don't need now a big file with all the tiles. I'm going to use GDAL build VRT, and it can work with a list of files that we can create, and then it will mosaic all the files in the list. To create a list we can use dir slash b, so it only lists the file names, and I only want the TIFF files, and I can write it to list dot text. So it created this list of the four TIFF files. Now I can use GDAL build VRT, and then we use this input file list, minus input file list, and then it is list dot text, and the output is dm mosaic dot VRT, and there it is. Here we see that it's added. The next step is to reproject the file, and we can use GDAL warp for that. With GDAL warp we can not only reproject, we can also cut it to a cut line, which in our case is the bounding box shape file, and we can crop it to that cut line, which means that we don't get no data values outside of the shape file, the boundary polygon, and we can of course define the projection of the output, in our case UTM zone 32 North, and the resampling method, which is default nearest neighbor, and we can control the output resolution. So the function will be GDAL warp to the projection 32632, with the resolution of 30 by 30 meters, which is the node data of the destination minus 9999 cut line, which is our shape file, and we crop it to the cut line, and there it is. So we now see that we have dm dot tiff, which is a cropped tiff file. And now we want it in PC raster format, so we use GDAL translate. GDAL translate is to translate from one raster format to another, and it has also different options here that you can read. And we are going to use PC raster. So if we go to the raster drivers and to PC raster, then we see here that we have to use this value scale, because PC raster is strict on the value scale. In our case it's dm, so it will be value scale scalar, and the scalar can be float 32 or float 64. Now if you interpret all this, then you will come to this command, output format, PC raster, output type float 32 would be sufficient for us. You can also use float 64. And then we have this extra creation options, mo, where we can type this vs scalar. So the output will be a scalar, and the input is dm dot tiff, and the output is dm dot map. Now it's done, and we can visualize it with the PC raster agilas software, and that is our dm in PC raster format. So with that we can proceed with PC raster python in spider. So in spider I'm going to use the console, because I'm not really making a model, I just want to delineate the catchment. So I'm going to import PC raster from PC raster import. And then the functions, another library is imported, so we can use the map algebra functions. And the first thing I need to do is read the dm. Call it dm equals readmap. And I have to set here the correct folder. That's where we work. So that's our working folder, readmap, and then I put there in quotes dm dot map. And that should work. So now dm variable is equivalent to the file. And the next thing that we are going to do with the dm is to fill it, because there are these artificial depressions. And to fill it we can use the lddcreate function. If you go to PC raster documentation under support, then you can find here all the operations. And to create a flow direction map we use lddcreate. And that will create a flow direction map based on all these different arguments. So here's a description how it works and these different arguments control all these different overflow levels. So we will just put this to a very high value, to make sure that it mostly fills all the depressions. So we are going to make a flow direction map that equals lddcreate. That's the function. And the first argument is the dm. And then we have 1, 2, 3, 4 other arguments, which we just make very large, to make sure that it fills up completely. That will take a bit in the calculation. And we can write it to the disk and then visualize it. So we can use report, flow direction, flow direction. Then I go back to the prompt and do agila, flow direction map. There it is. We need to zoom in to see the different lines. There it is. So PC raster visualizes the flow direction with these lines. And we can see here the direction for each pixel in compass direction. The next step is to define the rivers. So we can calculate the straller orders. We use the stream order function. The function uses the flow direction map as an input. So we can type straller equals stream order and then flow direction as an argument. And then we can write it to the disk using report, report straller. And we call it straller.map. So using the prompt we can now visualize the straller orders using agila. And here we see an ordinal map for the different numbers, the different straller orders. And what we can do is now choose a straller order. So I can say straller 8 for example equals if then straller larger than 8 then boolean 1 and I report it. So these are the streams with straller 8 or larger. To delineate the stream we need to identify the coordinate on the stream. So I'm just going to take it somewhere here and this will give us the coordinates written here. So I'm going to make a file. So this file will contain the two coordinates separate with a space and a unique identifier. So this is the x-coordinate. Then we do a space and the y-coordinate and the unique number. And then we close the file with Ctrl Z and then our location.text file is saved. PCRuster comes with a tool called toMap where we can convert these files into a PCRuster map. So we do call toMapLocation.textOutlet.map and it needs to fit of course the raster dimensions of the DEM which you can call clone. And it's also nominal data. So we can also give minus n to confirm that the output should be nominal. And there it is. So we can use the outlet. We read it from the file that we just created. Outlet.map. And then we can use that to delineate our catchment. There's the catchment function in PCRuster and it used the flow direction as an argument and then points, in this case one point of our outlet. So we can create it. WorkCatchment equals a catchment function and the arguments are then the flow direction and outlet and we report it to the disk so we can visualize it. Let's call it workCatchment.map and let's go to the prompt to visualize it. And there it is. So in this way we can use command line combining GDAL, PCRuster, Python to delineate catchment. And the hole in the middle by the way is caused by a very deep mine and the water in this case will flow around the mine and will not get stuck in the mine. Of course you can do this also with desktop software. You can use QGIS for example to delineate but with command line we will have more control that is happening and this output can then be further used in special dynamic modeling.