Context and question
I have a raster layer with slopes in percent and used the least cost path plugin in QGIS to calculate the least cost path from start to end. I try now to understand what the attribute value total_cost = 1428.691
in the resulting line layer represents. How is total_cost
calculated? This is probably software independet, but I used QGIS 3.30.0. Here the project and data can be found (all in one Geopackage file, 376 kB).
What I tried
My first idea was that it simply sums up the slope values of all cells touched by the path (sum of values in line 2 of all yellow cells in the screenshot below). To simulate this, I converted the raster to a polygon grid with same CRS (
EPSG:2056
), extent and resolution (0.5 m). I used select by expression to get all cells intersecting with the path (highlighted in yellow below), then created the sum ofslope
attributes of all selected cells. This resulted in a value of2111.342
, so ca. 33% larger than thetotal_cost
of the least cost path.My second try was to weight the slope by the length of the path inside each cell: so the slope of cells that are only marginally touched by the path are less weighted than cells where the path passes throught the whole cell. I calculated the length of the segement the least cost path passes through the cell (first line in the labels below), multiplied this with the slope value. This value is the third line in the screenshot. I then summed up the results for all yellow cells. Here, I got a value of
715.900
, about 50% of thetotal_cost
.Both approaches do not produce the same value as
total_cost
. So how istotal_cost
calculated?
Screenshot
red line= least cost path; blue cells=slope raster; yellow/selected cells=cells intersection with the least cost path; Labels represent: 1st line: length of the least cost path inside the current cell, 2nd line: slope of the current cell (in percents); last line: length multiplied by slope: