Q: I have a friction map, a start polygon and an end polygon and would like to find the least cost path, meaning not a corridor but a thin line. Themanual says: "If the input surface (a raster map layer) is a cumulative cost map generated by the or modules, the -d flag and a movement direction surface "indir" must be specified." I assume it's a kind of flow direction or aspect, but what is the physical meaning, and how can I calculate it?
A: The physical meaning is movement direction in degrees CCW from East, similar to e.g. flow direction output of. The direction map is an optional output of and , and should be used with the indir option for .
The workflow would thus be:
- convert the first polygon to a raster map
- use all cells of the first polygon as start points for r.walk, include the friction map
- convert the second polygon to a raster map
- use the second polygon as a MASK and get the coordinates of the cell with the lowest cost
- use these coordinates as start coordinates for r.drain, together with the movement direction map and the cumulative cost map produced by r.drain
A little example in the NC dataset:
# walking from Macon county to Dare county
g.region -p rast=elev_state_500m@PERMANENT
v.to.rast in=boundary_county@PERMANENT use=val val=1 where="NAME = 'DARE'" out=dare
v.to.rast in=boundary_county@PERMANENT use=val val=1 where="NAME = 'MACON'" out=macon
r.mapcalc "friction = 0.0001"
# use Knight's move r.walk elevation=elev_state_500m@PERMANENT friction=friction output=dare_cost outdir=dare_dir start_rast=dare -k
r.out.xyz in=dare_cost out=- | sort -t "|" -k 3 | head -n3
# gives # 234250|147750|490937.498669579 # 234250|147250|491132.5043559544 # 234250|146750|491258.3433474401
# Coordinates with lowest cost in Macon county are 234250,147750, and the lowest cost is > zero.
# use directions input because the input is a cost surface # and vector output because of Knight's move in r.walk
r.drain -d input=dare_cost indir=dare_dir output=macon2dare vector_output=macon2dare start_coordinates=234250,147750
Application of r.walk:
- Yang, M., van Coillie, F., Liu, M., De Wulf, R., Hens, L., & Ou, X. (2014). A GIS Approach to Estimating Tourists' Off-road Use in a Mountainous Protected Area of Northwest Yunnan, China. Mountain Research and Development, 34(2), 107-117. http://www.bioone.org/doi/full/10.1659/MRD-JOURNAL-D-13-00041.1