 Hello welcome back on my YouTube channel. In this video I'm going to demonstrate how to delineate the catchments that drain into a lake. Here you see a DEM, but inside this DEM is a lake. However the DEM has values there too, and we need to mask those if we want to delineate the catchments. We don't want those pixels to be taken into account in the delineation procedure. You need to follow the same procedure if you want to delineate catchments that drain into a sea or an ocean. First we need a lake polygon. We can download the lake polygon using the quick osm plugin which downloads features from OpenStreetMap. I install the plugin from the Plugins Manager. After installing the plugin I can click this icon and the first time I use it I need to accept the terms. To get the lakes I choose as key, natural and value, water. I define the extent as the layer extent of the DEM and I choose under advanced that I only want the multi polygons. Then I run the query. Now the lakes are downloaded. Note that also lakes outside of our area of interest are downloaded because the DEM extends the area with no data values. I select the polygon that we need and I click export save selected features to a geo package and let's create a new geo package which I call LakeData and I call this layer Lake. I change the projection to the one of the project and click OK. Now we have a new layer that only consists of the lake polygon that we need in the rest of the process. Let's style this layer. I'll just quickly do that in another video. I've covered how to do this in more detail. Now we can remove the downloaded lakes but we only have our lake and DEM left. Now I need to create a polygon layer with the extent of the study area and I use here expect layer extent. With this tool I can create a polygon with the layer extent. I choose the DEM and I save the result to LakeData and I call the layer extent. After clicking run you can now see that there is a polygon covering the extent of the DEM layer. The next step is that we need to cut the lake polygon out of this extent polygon and I use the difference tool. As an input I choose the extent polygon and as an overlay the lake polygon and in this way the algorithm will extract the features that are outside of this lake polygon. I save it to the same geo package and I call this layer difference. Here you see the result. Let's remove some layers. Here we see the extent polygon with a hole at the location of the lake and if I overlay it with the DEM then you see the part that we need to mask. We can mask the DEM now by using raster extraction clip raster by mask layer. As an input I choose the original DEM. As a mask layer I choose the difference polygon and I assign minus 9999 as the no data value and I keep the resolution of the input raster. In fact this makes a copy of the DEM but it masks the lake area to the no data value and I call the result DEM masked. Let's run it and here we see the result and that's the DEM with the masked lake. Because we are going to process this DEM with the PC raster tools plugin I'm going to convert this DEM to the PC raster data format. I use the convert to PC raster format tool. I choose DEM masked as an input. I choose scalar as the output data type because it's a continuous raster and I choose DEM lake masked dot map as the output file name. This just creates a copy in the PC raster format. The next step is to create a flow direction map. We use the LDD create tool which fills the syncs and results in the flow direction map. I keep the defaults and I save the result as flowdirection.map and here is the result. The next step is to use the pit tool to find all the outlets at the lake shore. The pit tool will find all the syncs that are left in our area. I call the result outlets.map. Now every pit has a unique value so I can style this with the palleted unique values renderer. I just use random colors and click specify. Now you see here that every pit at the lake shore has a unique value. We're going to use these outlets as the input for the catchment tool. Let's go back to the processing toolbox. There I choose the catchment tool. The catchment tool needs a flow direction layer as an input and the new outlets layer. I save the result as lake catchments. Then I run it and it delineates all the catchments related to the outlets. I can simply copy the style of the outlets to give the same colors to the delineated catchments and there is the result. Of course this also contains artifacts but you can correct those by removing the pits that you don't need or exporting only the polygons for your research. I hope this was useful. Please subscribe to my YouTube channel if you want to receive updates and looking forward to see you next time again.