 Hello, this is Hans van der Kwas senior lecturer at IHDELFT Institute for Water Education. In this video I am going to demonstrate how to do a least cost path analysis, which means I am going to calculate the best path, in this case from houses to accessible wells. The data that I use here is a result from a previous video on calculating the accessible wells based on certain criteria and using map algebra. So we have a layer with the final accessible and inaccessible wells, we have a layer with the land use, from which we can get the houses, we have a layer with roads, which have different classes for dirt road and tarmac, and we have a DTM. For this analysis I am going to use a plugin, which is called the least cost path plugin, and it adds a tool to the processing toolbox. And here you can give a cost raster, which has basically the friction. You need to add a start point layer and an end point layer, and the start point needs one point, and the end point can be multiple points, and then you can choose if you want to connect only to the nearest point or to all the points. We are going to create now all these input layers. So for the end point layer I only need the accessible wells, so I need to select the accessible wells from the attribute table, I use the select by expression tool, and all the accessible wells have a value one. Select those features and there are three wells, I am going to export the selection to a new file, and I call it accessible. Let's copy the style, and now we see the three points, and not the inaccessible wells. Now for the starting point I want the houses, so what I need to do is to create a new layer that only has the houses, and that's when buildG has value one. So here in the raster calculator it says if buildG equals one, then give me true, else give me false. So this will result in a raster with true and false, which is a Boolean raster. We can see that easily if we style it with the pelleted unique values, and there we see the two values. We need those houses as point factors, but then we only need to convert the values one to points, and the zeros need to be removed from the raster before we convert it. There's an easy trick to mask certain values, we go to extraction, clip, raster by extent, and we choose the extent from the same layer as we use the input layer, and then we choose a zero for the no data value, which means all the zeros will be masked, also the existing ones. Let's call the output houses no zero, and now we see what happened. Zeros have been removed, and the ones are still there. Now we can convert the raster pixels to points, and we use the houses no zero as an input, we can choose an output field name, where the ones will be stored, and I save this a vector, which will be our point vector, and let's style it. I'm going to choose an SVG marker, and I can search here for the images, new feature from 3.20, change the color, red, make it some bigger, remove the background raster, and now we see the houses on the DEM, and the wells to which the people need to go for their water. Now we need to create the friction layer, or the cost raster, and in this case we will use the roads, the tarmac roads should have much less cost, so less resistance, and the dirt road a little bit, and where there are no roads it needs to have a high cost to cross those pixels. So we're going to reclassify the roads layer using a reclassification table, lookup table. I add the original values, and I assign friction of 10 for the zeros, so where there's no roads, for 5 for where there is dirt roads, and 1 when it's tarmac. Make sure that you change the range boundaries to exact boundaries, use byte as output data type, and that's the friction, and now we see our houses, the wells to which they need to move, and the friction layer based on the roads. So now we have all the inputs to calculate the least cost path, so let's use the least cost path tool from the plugin, as a cost raster we choose road friction, band number 1, it only has one band, a start point layer we choose houses, but it needs 1 and it can use a selection, so let's select one of the houses, let's select this house and use road friction as the cost raster, band 1, houses as an input check, the box for selected feature only, and then for endpoint the accessible wells, and I want to see all the paths, so not the shortest one only, and here we see the paths, and if we open the attribute table, it gives us the paths and it gives us to which endpoint it goes and the total cost, and we see that the first one here has the least cost, and that's also what we can calculate, so let's fill in the form again, road friction, band 1, start point houses, selected features only, endpoint the accessible wells, and then only connect with the nearest endpoint, so with the least cost, hide the other one, style to make it clearer, and let's zoom in a bit, so here we see that from the selected house to the well over there has the least cost, while the other one is closer, but then you need to cross the dirt road, we can improve our friction map a bit by including the slope, so go to raster analysis, and calculate the slope, choose the DTM as an input, and I can keep it as degrees, it depends on how much weight you want to give it if you want degrees, or if you want percentage, or even if you want to reclassify the slopes into classes, here I just use degrees for this hypothetical example, and what you see here is that when we calculate the slope, which is a focal function, we use a row and a column on the edges, there is a function to compute the edges, if you'll do some kind of interpolation, and because you see that there are houses here on the edge, I'm going to use that and call it slope edge, and just recalculate slope, and now you see that it fits the whole DTM, so just remember that when you calculate slope, normally you will lose the sides, so you need to choose your area a little bit bigger than you exactly need, so now I want to combine this with our road friction map, so I'm going to do is simply multiply them, it's just a model that we are making, so the friction of the roads times the slope will give a total friction, and I call it road slope friction, there it is, and let's use this then for the least cost path and see if it changes, use road slope friction, houses, selected feature, accessible wells, let's calculate all of them, there we have the paths, and we see that we have a higher total cost than we had before, but that's still, that route is the best one to get well from that house, now let's calculate the best path from all the houses to the accessible wells, so we use road slope friction, starting point houses, and there I use this green arrow, then it will iterate over all the features in houses and do it independently for all to the accessible wells, I only want the nearest one, so the most effective one, then I click run and it produces all the outputs, now it's done, all the layers are added to the layers panel, which looks a bit messy now, so let's group this, so we can easily see the other layers now, and here we see the network of routes that people need to take to the wells, and you can find then the total cost there for each line, and the IDs, they resemble the IDs of the houses that we had, and of the wells, but it might be easier to have them all in one layer, so I'm going to merge these different lines to one new vector layer, select them all and unselect the ones we don't need, that's easier, call it paths and 149 paths are stored now in one vector file, move it out of the group, and here we see everything in one attribute table, so I can sort on the cost, and I can see here that this one that I select is the least cost, but all these lines are overlapping, so it's a bit hard to see, it's more interesting also to look at which one has the most cost, so which household is furthest from an accessible well, that's this one, and to make it clear what the route is from this house to an accessible well, we're going to export their route to a new vector, let's call it longest path, style it a bit to make it clearer, so this is the longest path, but then we also would like to know how long it really is, we know how much cost it is from the attribute table, but what is the distance in meters, that's total cost, go to the field calculator, create a new field, I call it distance, so a decimal number, and we use dollar length, and that will calculate the length of the line and add it to the attribute table, and here we see that it's around three and a half kilometers, so in this video you've learned how to create the least cost path from source points to destination points by using a friction layer that we also created.