1r.cost(1) Grass User's Manual r.cost(1)
2
3
4
6 r.cost - Outputs a raster map layer showing the cumulative cost of
7 moving between different geographic locations on an input raster map
8 layer whose cell category values represent cost.
9
11 raster
12
14 r.cost
15 r.cost help
16 r.cost [-vknr] input=name output=name [start_points=string]
17 [stop_points=string] [start_rast=string] [coordinate=x,y[,x,y,...]]
18 [stop_coordinate=x,y[,x,y,...]] [max_cost=cost] [null_cost=null
19 cost] [percent_memory=percent memory] [--overwrite]
20
21 Flags:
22 -v Run verbosely
23
24 -k Use the 'Knight's move'; slower, but more accurate
25
26 -n Keep null values in output map
27
28 -r Start with values in raster map
29
30 --overwrite
31
32 Parameters:
33 input=name
34 Name of raster map containing grid cell cost information
35
36 output=name
37 Name for output raster map
38
39 start_points=string
40 Starting points vector map
41
42 stop_points=string
43 Stop points vector map
44
45 start_rast=string
46 Starting points raster file
47
48 coordinate=x,y[,x,y,...]
49 The map E and N grid coordinates of a starting point (E,N)
50
51 stop_coordinate=x,y[,x,y,...]
52 The map E and N grid coordinates of a stopping point (E,N)
53
54 max_cost=cost
55 An optional maximum cumulative cost Default: 0
56
57 null_cost=null cost
58 Cost assigned to null cells. By default, null cells are excluded
59
60 percent_memory=percent memory
61 Percent of map to keep in memory Default: 100
62
64 r.cost determines the cumulative cost of moving to each cell on a cost
65 surface (the input raster map) from other user-specified cell(s) whose
66 locations are specified by their geographic coordinate(s). Each cell in
67 the original cost surface map will contain a category value which rep‐
68 resents the cost of traversing that cell. r.cost will produce an output
69 raster map in which each cell contains the lowest total cost of
70 traversing the space between each cell and the user-specified points.
71 (Diagonal costs are multiplied by a factor that depends on the dimen‐
72 sions of the cell.) This program uses the current geographic region
73 settings. The output map will be of the same data format as the input
74 map, integer or floating point.
75
77 The input name is the name of a raster map whose category values repre‐
78 sent the surface cost. The output name is the name of the resultant
79 raster map of cumulative cost.
80
81 r.cost can be run with three different methods of identifying the
82 starting point(s). One or more points (geographic coordinate pairs) can
83 be provided as specified coordinates on the command line, from a vector
84 points file, or from a raster map. All non-NULL cells are considered
85 to be starting points. Each x,y coordinate pair gives the geographic
86 location of a point from which the transportation cost should be fig‐
87 ured. As many points as desired can be entered by the user. These
88 starting points can also be read from a vector points file through the
89 start_sites option or from a raster map through the start_rast option.
90
91 r.cost will stop cumulating costs when either max_cost is reached, or
92 one of the stop points given with stop_coordinates is reached. Alter‐
93 natively, the stop points can be read from a vector points file with
94 the stop_sites option. During execution, once the cumulative cost to
95 all stopping points has been determined, processing stops. Both sites
96 read from a vector points file and those given on the command line will
97 be processed.
98
99 The null cells in the input map can be assigned a (positive floating
100 point) cost with the null_cost option.
101 When input map null cells are given a cost with the null_cost option,
102 the corresponding cells in the output map are no longer null cells. By
103 using the -n flag, the null cells of the input map are retained as null
104 cells in the output map.
105
106 As r.cost can run for a very long time, it can be useful to use the -v
107 verbose flag to track progress.
108
109 The Knight's move (-k flag) may be used to improve the accuracy of the
110 output. In the diagram below, the center location (O) represents a grid
111 cell from which cumulative distances are calculated. Those neighbors
112 marked with an X are always considered for cumulative cost updates.
113 With the -k option, the neighbors marked with a K are also considered.
114 . . . . . . . . . . . . . . .
115 . . . K . . K . . .
116 . . . . . . . . . . . . . . .
117 . . K . X . X . X . K . .
118 . . . . . . . . . . . . . . .
119 . . . X . O . X . . .
120 . . . . . . . . . . . . . . .
121 . . K . X . X . X . K . .
122 . . . . . . . . . . . . . . .
123 . . . K . . K . . .
124 . . . . . . . . . . . . . . .
125
126 Knight's move example: | Flat cost surface without (left pane) and with
127 the knight's move (right pane). The default is to grow the cost out‐
128 wards in 8 directions. Using the knight's move grows it outwards in 16
129 directions.
130
132 By default null cells in the input raster map are excluded from the
133 algorithm, and thus retained in the output map.
134
135 If one wants r.cost to transparently cross any region of null cells,
136 the null_cost=0.0 option should be used. Then null cells just propagate
137 the adjacent costs. These cells can be retained as null cells in the
138 output map by using the -n flag.
139
141 Sometimes, when the differences among integer cell category values in
142 the r.cost cumulative cost surface output are small, this cumulative
143 cost output cannot accurately be used as input to r.drain (r.drain will
144 output bad results). This problem can be circumvented by making the
145 differences between cell category values in the cumulative cost output
146 bigger. It is recommended that, if the output from r.cost is to be used
147 as input to r.drain, the user multiply the input cost surface map to
148 r.cost by the value of the map's cell resolution, before running
149 r.cost. This can be done using r.mapcalc. The map resolution can be
150 found using g.region. This problem doesn't arise with floating point
151 maps.
152
153 Algorithm notes
154 The fundamental approach to calculating minimum travel cost is as fol‐
155 lows:
156
157 The user generates a raster map indicating the cost of traversing each
158 cell in the north-south and east-west directions. This map, along with
159 a set of starting points are submitted to r.cost. The starting points
160 are put into a list cells from which costs to the adjacent cells are to
161 be calculated. The cell on the list with the lowest cumulative cost is
162 selected for computing costs to the neighboring cells. Costs are com‐
163 puted and those cells are put on the list and the originating cell is
164 finalized. This process of selecting the lowest cumulative cost cell,
165 computing costs to the neighbors, putting the neighbors on the list and
166 removing the originating cell from the list continues until the list is
167 empty.
168
169 The most time consuming aspect of this algorithm is the management of
170 the list of cells for which cumulative costs have been at least ini‐
171 tially computed. r.cost uses a binary tree with an linked list at each
172 node in the tree for efficiently holding cells with identical cumula‐
173 tive costs.
174
175 r.cost, like most all GRASS raster programs, is also made to be run on
176 maps larger that can fit in available computer memory. As the algorithm
177 works through the dynamic list of cells it can move almost randomly
178 around the entire area. r.cost divides the entire area into a number of
179 pieces and swaps these pieces in and out of memory (to and from disk)
180 as needed. This provides a virtual memory approach optimally designed
181 for 2-D raster maps. The amount of map to hold in memory at one time
182 can be controlled with the percent_memory option. For large maps this
183 value will have to be set to a lower value.
184
186 Consider the following example:
187 Input:
188 COST SURFACE
189 . . . . . . . . . . . . . . .
190 . 2 . 2 . 1 . 1 . 5 . 5 . 5 .
191 . . . . . . . . . . . . . . .
192 . 2 . 2 . 8 . 8 . 5 . 2 . 1 .
193 . . . . . . . . . . . . . . .
194 . 7 . 1 . 1 . 8 . 2 . 2 . 2 .
195 . . . . . . . . . . . . . . .
196 . 8 . 7 . 8 . 8 . 8 . 8 . 5 .
197 . . . . . . . . . . _____ . .
198 . 8 . 8 . 1 . 1 . 5 | 3 | 9 .
199 . . . . . . . . . . |___| . .
200 . 8 . 1 . 1 . 2 . 5 . 3 . 9 .
201 . . . . . . . . . . . . . . .
202 Output (using -k): Output (not using -k):
203 CUMULATIVE COST SURFACE CUMULATIVE COST SURFACE
204 . . . . . . . . . . . . . . . . . . . * * * * * . . . . . .
205 . 21. 21. 20. 19. 17. 15. 14. . 22. 21* 21* 20* 17. 15. 14.
206 . . . . . . . . . . . . . . . . . . . * * * * * . . . . . .
207 . 20. 19. 22. 19. 15. 12. 11. . 20. 19. 22* 20* 15. 12. 11.
208 . . . . . . . . . . . . . . . . . . . . . * * * * * . . . .
209 . 22. 18. 17. 17. 12. 11. 9. . 22. 18. 17* 18* 13* 11. 9.
210 . . . . . . . . . . . . . . . . . . . . . * * * * * . . . .
211 . 21. 14. 13. 12. 8. 6. 6. . 21. 14. 13. 12. 8. 6. 6.
212 . . . . . . . . . . _____. . . . . . . . . . . . . . . . .
213 . 16. 13. 8. 7. 4 | 0 | 6. . 16. 13. 8. 7 . 4. 0. 6.
214 . . . . . . . . . . |___|. . . . . . . . . . . . . . . . .
215 . 14. 9. 8. 9. 6. 3. 8. . 14. 9. 8. 9 . 6. 3. 8.
216 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
217
218
219 The user-provided ending location in the above example is the boxed 3
220 in the above input map. The costs in the output map represent the total
221 cost of moving from each box ("cell") to one or more (here, only one)
222 starting location(s). Cells surrounded by asterisks are those that are
223 different between operations using and not using the Knight's move (-k)
224 option.
225
226 Output analysis
227 The output map can be viewed, for example, as an elevation model in
228 which the starting location(s) is/are the lowest point(s). Outputs from
229 r.cost can be used as inputs to r.drain, in order to trace the least-
230 cost path given by this model between any given cell and the r.cost
231 starting location(s). The two programs, when used together, generate
232 least-cost paths or corridors between any two map locations (cells).
233
234 Shortest distance surfaces
235 The r.cost module allows for computing the shortest distance of each
236 pixel from raster lines, such as determining the shortest distances of
237 households to the nearby road. For this cost surfaces with cost value 1
238 are used. The calculation is done with r.cost as follows (example for
239 Spearfish region):
240 g.region rast=roads -p
241 r.mapcalc "area.one=1"
242 r.cost -k input=area.one output=distance start_rast=roads
243 d.rast distance
244 d.rast.num distance
245 #transform to metric distance from cell distance using the raster
246 resolution:
247 r.mapcalc "dist_meters=distance * (ewres()+nsres())/2."
248 d.rast dist_meters
249
250
252 The percentage done calculation reported in verbose mode is often not
253 linear and ends well before 100%. This does not affect output.
254
256 r.drain, r.walk, r.in.ascii, r.mapcalc, r.out.ascii
257
259 Antony Awaida,
260 Intelligent Engineering
261 Systems Laboratory,
262 M.I.T.
263 James Westervelt,
264 U.S.Army Construction Engineering Research Laboratory
265
266 Updated for Grass 5
267 Pierre de Mouveaux (pmx@audiovu.com)
268
269 Last changed: $Date: 2006/04/18 02:55:35 $
270
271 Full index
272
273
274
275GRASS 6.2.2 r.cost(1)