 Hello, this is Hans van der Klaas, senior lecturer at IHC Delft Institute for Water Education. In this video, I'll demonstrate how to model pollution with runoff over the flow direction map. We will use the PCRuster tools in QGIS that runs on KONDA. Have a look at other videos on how to set up this environment. We'll start with data from SRTM, which has already been re-projected and clipped to the study area. Let's go to the Processing Toolbox and under Scripts. We first need to use the Convert to PCRuster Format tool. We choose the DEM as input and the output data type should be scalar because it's a continuous roster and let's save it as DEM.map. We always need to convert to the PCRuster format in order to use these tools from PCRuster. I remove the layer that I don't need anymore. The next step is to create our local drain direction map or the flow direction map and it uses a DEM and in the documentation you can read what all these parameters mean, but we use a maximum filled elevation model for this flow direction map. Therefore, we have these high values as parameters. Calculation takes a while and there is the result. Let's also add OpenStreetMap there for our reference where we can put our pollution point. Let's make a temporary scratch layer to digitize our points where the pollution is taking place like point sources and I want them to have an ID number as a whole number. Now I can digitize the points, just put them randomly to test this algorithm and I toggle off editing and save our edits. Now we need to convert this to a roster because with PCRuster we can only use roster layers, so I go to Raster, Conversion, Rasterize, I choose the points and I select the fields with the IDs, I set to GeoReferenceUnits and use spatial resolution of 30 meter pixels. The output extent let's use there the DEM or the LED, that doesn't matter and later we will re-sample also the roster layers to make sure that they have the same dimensions, which is necessary for map algebra. So we'll save this to Pollution.tiv and now it's a roster file, it shows some strange random values but if we use the palleted unique values then we see that there are five roster points of 30 meter pixels not very visible on the map because they're very small but this is how we can continue. Now we can convert this layer to the PCRuster format, so look for the convert to PCRuster format tool, choose the pollution layer, output data type is nominal because these are classes which don't have a specific order and make sure that you save it as a .map file so you need to change the file type to .map and there is the result, we can copy the style and paste it to our new result which also has the five classes, which we can verify if we click classify. The next step is to re-sample this to the same dimensions as the LVD because for map algebra all the roster layers need to have the same properties, cell size and extent and because we did some conversions with GDAL we're not sure if this is exactly the same so therefore we use re-sample, let's call it pollutionR.map and let's see if the data is still the same as the input with the five classes and that's indeed the case. The tools that we are going to use however don't need missing value in the background but zeros so I'm going to make a layer with only zeros in the same data type nominal, I can choose here any of the mask layers that are correct with the dimensions and I call this layer nominal zero so we can merge it later with our pollution layer. So here we have a roster with only zeros in nominal values, to combine both layers we use the cover tool so with cover you can choose a roster layer that has missing values in our case pollutionR and then choose the layers with which you want to cover the missing values that can be one or more layers and that will be applied in that order. Let's call the output pollutionNominal and I run the tool and I style the result with palleted unique values you see that now also the zeros are added at the place of the missing values so now our pollution input layer is ready to be routed over the landscape using the local drain direction and we used two tools for that spreadLDD and spreadLDDZone but these tools need an initial friction and the friction layer and we don't have that yet so we will make that and we can do that with the spatial tool again by setting all the pixels to zero scalar in the mask and this initial friction of zero will determine that there is no friction at the starting point of routing so therefore it's zero and then the friction will be set to one so scalar and that means that crossing a pixel as a unit of one so the pixel length basically and you can also use other layers for that if there is another type of friction that you want to use but here we use zero and one so we can now add that to this spread LDD tool where we use the local drain direction as an input for the points roster we use the pollution nominal that we created initial friction scalar zero and the friction scalar one then write it to the file and we call spreadLDD pollution and when I run it I get this layer and makes more sense to style it it's a continuous layer which contains the distance over the flow direction to the pollution from the pollution to the outlet do you see it in colors of course in our case the flows overlap of the different points so there it has to make choices so you need to look at it carefully when you interpret it and you can of course also follow it over the open street map layer let's do LDD zone with the same inputs the difference is that this will assign the value of the points to the route that it takes over the flow direction so as expected we will have a nominal output so I use pelleted unique values which gives a unique number to each flow which is the same value as the points that we used for the pollution and I've removed the zero and here we see in different colors but of course here we also have overlap so so be careful with that interpretation but this is a way to see the flow paths of the different pollution points that we have indicated in the landscape another tool that we can use as the path tool which only needs the flow direction the LDD layer and our pollution points when I run it I get an error and if you read this error it says that the type is nominal while the legal type is Boolean PC Rust is really strict on that so you should always check the help file and we can solve this easily by converting the data type of our pollution points so pollution nominal and we're going to change it to Boolean because the path tool expects a Boolean input so all the pollution points will be one and the zeros will remain zero and then we can fill it in again with the Boolean input and here we have the paths of the pollution in a Boolean result layer so path and no path so this was a lot of steps to reach the result and it would be much more practical to combine this into a model where the user can just have the LDD as an input because it takes a lot of time to calculate so we do that only once and the points with pollution and that it will automatically generate the outputs for the pollution paths we can do that in the graphical modeler so let's start let's first give our model a name call it pollution and the group under which it will show up in the processing toolbox under the model tools and I'm going to define the inputs that the user needs to provide that's first a vector layer with the pollution source and the user should also indicate the field that is used for the values remember in our case we have nominal values of different IDs of the points so that should be indicated and the other layer that the user needs to provide is the local drain direction roster now we're going to add the tools exactly as we did in the steps that I presented before so first we need to rasterize the points does an input we use the pollution source and as the field we also use the model input for the field output raster size like we filled it in in the tool before 30 meters georeferenced units and the output extent should be the same as the local drain direction and there is our tool the next step was to convert this then to a PC raster format so make sure to choose their the output from rasterized and we need it as a nominal PC raster map then the next step was to resample and there we use the algorithm output from the conversion to PC raster format and we use the local drain direction as an input and I'm going to report the output because it's always good if you make these models to check if the different parts work I'm going to save the model and then I can run it and I already see that the order of the input is not really a logical for the user so I want the pollution source input first on the form and then the field and then the local drain direction so you can determine that order save it and I'm going to make a dummy pollution layer again with numeric ID fields add again a couple of points in the landscape save it and run our preliminary model and see if it works it worked so that part of the model is okay then we continue and if you don't define an output then it will be in memory so the next algorithm that I need to use is to add the nominal zeros into the data so I create with the spatial tool a layer with nominal zero values for all the pixels that are in the local drain direction map that we use as a mask and then with cover I can combine the pollution classes with zero for the no data pixels so I use the pc ruster layer and as an input I use there for the cover the nominal zero and let's also test this part the limit state there you can see it from the connections let's see if it runs and also this one runs without an error so that means it's okay you can also check the layer that comes out but as long as I don't see errors I believe that it will be correct in this case now I need this two more spatial layers with one value the friction the initial friction and the friction layers I'm going to make one with scale r zero use the ldd again as a mask and that will be our initial friction and then scale r1 in a similar way that will be the friction layer could also make that variable if the user has a friction map if that's part of the model between now just replicating it for an ordinary case and then we can apply spread ldd use the local drain direction raster from the input and then the cover layer which has our nominal classes including the zero initial friction scale r zero and the friction scale r1 and that's also what we want to see as an output so therefore we type here a name for the output so that will be included as a dialogue entry where the user can type or choose the layer name of the output so that will be in the green box here and same for spread ldd zone same layers as an input and also give it a name because we want to have the output let's reorganize it a bit save the model and here it looks okay as we want it if we run it it runs without problem and let's see if it produced the results yes they are there and now let's remove the input and see how we'll bust it is if we run it from the processing toolbox so i'm going to create a new pollution layer this can be any vector layer that you have with pollution points or areas or lines that doesn't really matter because it will be converted to raster in our case it's easy to add a few points save it and we find the model here the processing toolbox we find the inputs and run the model and there it is a bit of styling to see the result these are the pollution points and then with colors the different paths for each point and then we also have the ldd distance results to be single them to the color i inverted so the further and it's in in map units so in meters so the further from the points the more red of course here with interpretation we also have these overlaps so we have created a nice tool to route pollution over the flow direction