.TH r.cost 1grass "" "GRASS 6.4.4" "Grass User's Manual" .SH NAME \fI\fBr.cost\fR\fR - Creates a raster map showing the cumulative cost of moving between different geographic locations on an input raster map whose cell category values represent cost. .SH KEYWORDS raster, cost surface, cumulative costs .SH SYNOPSIS \fBr.cost\fR .br \fBr.cost help\fR .br \fBr.cost\fR [\-\fBknrv\fR] \fBinput\fR=\fIname\fR \fBoutput\fR=\fIname\fR [\fBoutdir\fR=\fIstring\fR] [\fBstart_points\fR=\fIname\fR] [\fBstop_points\fR=\fIname\fR] [\fBstart_rast\fR=\fIname\fR] [\fBcoordinate\fR=\fIx,y\fR[,\fIx,y\fR,...]] [\fBstop_coordinate\fR=\fIx,y\fR[,\fIx,y\fR,...]] [\fBmax_cost\fR=\fIcost\fR] [\fBnull_cost\fR=\fInull cost\fR] [\fBpercent_memory\fR=\fIpercent memory\fR] [\-\-\fBoverwrite\fR] [\-\-\fBverbose\fR] [\-\-\fBquiet\fR] .SS Flags: .IP "\fB\-k\fR" 4m .br Use the 'Knight's move'; slower, but more accurate .IP "\fB\-n\fR" 4m .br Keep null values in output raster map .IP "\fB\-r\fR" 4m .br Start with values in raster map .IP "\fB\-v\fR" 4m .br Run verbosely .IP "\fB\-\-overwrite\fR" 4m .br Allow output files to overwrite existing files .IP "\fB\-\-verbose\fR" 4m .br Verbose module output .IP "\fB\-\-quiet\fR" 4m .br Quiet module output .PP .SS Parameters: .IP "\fBinput\fR=\fIname\fR" 4m .br Name of raster map containing grid cell cost information .IP "\fBoutput\fR=\fIname\fR" 4m .br Name for output raster map .IP "\fBoutdir\fR=\fIstring\fR" 4m .br Name of output raster map to contain movement directions .IP "\fBstart_points\fR=\fIname\fR" 4m .br Name of starting vector points map .IP "\fBstop_points\fR=\fIname\fR" 4m .br Name of stop vector points map .IP "\fBstart_rast\fR=\fIname\fR" 4m .br Name of starting raster points map .IP "\fBcoordinate\fR=\fIx,y[,\fIx,y\fR,...]\fR" 4m .br Map grid coordinates of a starting point (E,N) .IP "\fBstop_coordinate\fR=\fIx,y[,\fIx,y\fR,...]\fR" 4m .br Map grid coordinates of a stopping point (E,N) .IP "\fBmax_cost\fR=\fIcost\fR" 4m .br Optional maximum cumulative cost .br Default: \fI0\fR .IP "\fBnull_cost\fR=\fInull cost\fR" 4m .br Cost assigned to null cells. By default, null cells are excluded .IP "\fBpercent_memory\fR=\fIpercent memory\fR" 4m .br Percent of map to keep in memory .br Default: \fI100\fR .PP .SH DESCRIPTION .PP \fIr.cost\fR determines the cumulative cost of moving to each cell on a \fIcost surface\fR (the \fBinput\fR raster map) from other user-specified cell(s) whose locations are specified by their geographic coordinate(s). Each cell in the original cost surface map will contain a category value which represents the cost of traversing that cell. \fIr.cost\fR will produce 1) an \fBoutput\fR raster map in which each cell contains the lowest total cost of traversing the space between each cell and the user-specified points (diagonal costs are multiplied by a factor that depends on the dimensions of the cell) and 2) a second raster map layer showing the movement direction to the next cell on the path back to the start point (see Movement Direction). This program uses the current geographic region settings. The \fBoutput\fR map will be of the same data format as the \fBinput\fR map, integer or floating point. .SH OPTIONS The \fBinput\fR \fIname\fR is the name of a raster map whose category values represent the surface cost. The \fBoutput\fR \fIname\fR is the name of the resultant raster map of cumulative cost. The \fBoutdir\fR \fIname\fR is the name of the resultant raster map of movement directions (see Movement Direction). .PP \fIr.cost\fR can be run with three different methods of identifying the starting point(s). One or more points (geographic coordinate pairs) can be provided as specified \fBcoordinate\fRs on the command line, from a vector points file, or from a raster map. All non-NULL cells are considered to be starting points. Each \fIx,y\fR \fBcoordinate\fR pair gives the geographic location of a point from which the transportation cost should be figured. As many points as desired can be entered by the user. These starting points can also be read from a vector points file through the \fBstart_points\fR option or from a raster map through the \fBstart_rast\fR option. .PP \fIr.cost\fR will stop cumulating costs when either \fBmax_cost\fR is reached, or one of the stop points given with \fBstop_coordinates\fR is reached. Alternatively, the stop points can be read from a vector points file with the \fBstop_points\fR option. During execution, once the cumulative cost to all stopping points has been determined, processing stops. Both sites read from a vector points file and those given on the command line will be processed. .PP The null cells in the \fBinput\fR map can be assigned a (positive floating point) cost with the \fBnull_cost\fR option. .br When input map null cells are given a cost with the \fBnull_cost\fR option, the corresponding cells in the output map are no longer null cells. By using the \fB-n\fR flag, the null cells of the input map are retained as null cells in the output map. .PP As \fIr.cost\fR can run for a very long time, it can be useful to use the \fB-v\fR verbose flag to track progress. .PP The Knight's move (\fB-k\fR flag) may be used to improve the accuracy of the output. In the diagram below, the center location (O) represents a grid cell from which cumulative distances are calculated. Those neighbors marked with an X are always considered for cumulative cost updates. With the \fB-k\fR option, the neighbors marked with a K are also considered. \fC .DS .br . . . . . . . . . . . . . . . .br . . . K . . K . . . .br . . . . . . . . . . . . . . . .br . . K . X . X . X . K . . .br . . . . . . . . . . . . . . . .br . . . X . O . X . . . .br . . . . . . . . . . . . . . . .br . . K . X . X . X . K . . .br . . . . . . . . . . . . . . . .br . . . K . . K . . . .br . . . . . . . . . . . . . . . .br .DE \fR .br Knight's move example: .br | \fIFlat cost surface without (left pane) and with the knight's move (right pane). The default is to grow the cost outwards in 8 directions. Using the knight's move grows it outwards in 16 directions.\fR .SH NULL CELLS .PP By default null cells in the input raster map are excluded from the algorithm, and thus retained in the output map. .PP If one wants \fBr.cost\fR to transparently cross any region of null cells, the \fBnull_cost\fR=0.0 option should be used. Then null cells just propagate the adjacent costs. These cells can be retained as null cells in the output map by using the \fB-n\fR flag. .SH NOTES .PP Sometimes, when the differences among integer cell category values in the \fIr.cost\fR cumulative cost surface output are small, this cumulative cost output cannot accurately be used as input to \fIr.drain\fR (\fIr.drain\fR will output bad results). This problem can be circumvented by making the differences between cell category values in the cumulative cost output bigger. It is recommended that, if the output from \fIr.cost\fR is to be used as input to \fIr.drain\fR, the user multiply the input cost surface map to \fIr.cost\fR by the value of the map's cell resolution, before running \fIr.cost\fR. This can be done using \fIr.mapcalc\fR. The map resolution can be found using \fIg.region\fR. This problem doesn't arise with floating point maps. .SS Algorithm notes The fundamental approach to calculating minimum travel cost is as follows: .PP The user generates a raster map indicating the cost of traversing each cell in the north-south and east-west directions. This map, along with a set of starting points are submitted to \fIr.cost\fR. The starting points are put into a list cells from which costs to the adjacent cells are to be calculated. The cell on the list with the lowest cumulative cost is selected for computing costs to the neighboring cells. Costs are computed and those cells are put on the list and the originating cell is finalized. This process of selecting the lowest cumulative cost cell, computing costs to the neighbors, putting the neighbors on the list and removing the originating cell from the list continues until the list is empty. .PP The most time consuming aspect of this algorithm is the management of the list of cells for which cumulative costs have been at least initially computed. \fIr.cost\fR uses a binary tree with an linked list at each node in the tree for efficiently holding cells with identical cumulative costs. .PP \fIr.cost\fR, like most all GRASS raster programs, is also made to be run on maps larger that can fit in available computer memory. As the algorithm works through the dynamic list of cells it can move almost randomly around the entire area. \fIr.cost\fR divides the entire area into a number of pieces and swaps these pieces in and out of memory (to and from disk) as needed. This provides a virtual memory approach optimally designed for 2-D raster maps. The amount of map to hold in memory at one time can be controlled with the \fBpercent_memory\fR option. For large maps this value will have to be set to a lower value. .SH EXAMPLES .PP Consider the following example: \fC .DS .br Input: .br COST SURFACE .br . . . . . . . . . . . . . . . .br . 2 . 2 . 1 . 1 . 5 . 5 . 5 . .br . . . . . . . . . . . . . . . .br . 2 . 2 . 8 . 8 . 5 . 2 . 1 . .br . . . . . . . . . . . . . . . .br . 7 . 1 . 1 . 8 . 2 . 2 . 2 . .br . . . . . . . . . . . . . . . .br . 8 . 7 . 8 . 8 . 8 . 8 . 5 . .br . . . . . . . . . . _____ . . .br . 8 . 8 . 1 . 1 . 5 | \fB3\fR | 9 . .br . . . . . . . . . . |___| . . .br . 8 . 1 . 1 . 2 . 5 . 3 . 9 . .br . . . . . . . . . . . . . . . .br .br .br Output (using \-k): Output (not using \-k): .br CUMULATIVE COST SURFACE CUMULATIVE COST SURFACE .br . . . . . . . . . . . . . . . . . . . \fB* * * * *\fR . . . . . . .br . 21. 21. 20. 19. 17. 15. 14. . 22. 21\fB* 21* 20*\fR 17. 15. 14. .br . . . . . . . . . . . . . . . . . . . \fB* * * * *\fR . . . . . . .br . 20. 19. 22. 19. 15. 12. 11. . 20. 19. 22\fB* 20*\fR 15. 12. 11. .br . . . . . . . . . . . . . . . . . . . . . \fB* * * * *\fR . . . . .br . 22. 18. 17. 17. 12. 11. 9. . 22. 18. 17\fB* 18* 13*\fR 11. 9. .br . . . . . . . . . . . . . . . . . . . . . \fB* * * * *\fR . . . . .br . 21. 14. 13. 12. 8. 6. 6. . 21. 14. 13. 12. 8. 6. 6. .br . . . . . . . . . . _____. . . . . . . . . . . . . . . . . .br . 16. 13. 8. 7. 4 | \fB0\fR | 6. . 16. 13. 8. 7 . 4. 0. 6. .br . . . . . . . . . . |___|. . . . . . . . . . . . . . . . . .br . 14. 9. 8. 9. 6. 3. 8. . 14. 9. 8. 9 . 6. 3. 8. .br . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .br .DE \fR .PP The user-provided ending location in the above example is the boxed \fB3\fR in the above input map. The costs in the output map represent the total cost of moving from each box ("cell") to one or more (here, only one) starting location(s). Cells surrounded by asterisks are those that are different between operations using and not using the Knight's move (\fB-k\fR) option. .SS Output analysis The output map can be viewed, for example, as an elevation model in which the starting location(s) is/are the lowest point(s). Outputs from \fIr.cost\fR can be used as inputs to \fIr.drain\fR with the direction flag \fB-d\fR, in order to trace the least-cost path given by this model between any given cell and the \fIr.cost\fR starting location(s). The two programs, when used together, generate least-cost paths or corridors between any two map locations (cells). .SS Shortest distance surfaces The \fIr.cost\fR module allows for computing the shortest distance of each pixel from raster lines, such as determining the shortest distances of households to the nearby road. For this cost surfaces with cost value 1 are used. The calculation is done with \fIr.cost\fR as follows (example for Spearfish region): \fC .DS .br g.region rast=roads \-p .br r.mapcalc "area.one=1" .br r.cost \-k input=area.one output=distance start_rast=roads .br d.rast distance .br d.rast.num distance .br .br #transform to metric distance from cell distance using the raster resolution: .br r.mapcalc "dist_meters=distance * (ewres()+nsres())/2." .br d.rast dist_meters .br .DE \fR .SH Movement Direction .PP The movement direction surface is created to record the sequence of movements that created the cost accumulation surface. Without it \fIr.drain\fR would not correctly create a path from an end point back to the start point. The direction shown in each cell points \fBaway\fR from the cell that came before it. The directions are recorded as \fC .DS .br 112.5 90 67.5 i.e. a cell with the value 135 .br 157.5 135 0 45 22.5 means the cell \fBbefore\fR it is .br 180 x 0 to the south-east. .br 202.5 225 270 315 337.5 .br 247.5 292.5 .br .DE \fR .PP Once \fIr.cost\fR computes the cumulative cost map, \fIr.drain\fR can be used to find the minimum cost path. Make sure to use the \fB-d\fR flag and the movement direction raster map when running r.drain to ensure the path is computed according to the proper movement directions. .SH BUGS The percentage done calculation reported in verbose mode is often not linear and ends well before 100%. This does not affect output. .SH SEE ALSO \fIr.drain\fR, \fIr.walk\fR, \fIr.in.ascii\fR, \fIr.mapcalc\fR, \fIr.out.ascii\fR .SH AUTHOR Antony Awaida, .br Intelligent Engineering .br Systems Laboratory, .br M.I.T. .br .br James Westervelt, .br U.S.Army Construction Engineering Research Laboratory .PP Updated for Grass 5 .br Pierre de Mouveaux (pmx@audiovu.com) .PP \fILast changed: $Date: 2013-03-26 22:18:02 +0100 (Tue, 26 Mar 2013) $\fR .PP Full index .PP © 2003-2014 GRASS Development Team