I would like to run the r.walk grass function with these codes:

import processing
from qgis.core import QgsRasterLayer
from PyQt4.QtCore import QFileInfo
path= 'd:/Works/_EvacuationSimulation/_raster/walk/'
filename1 = 'elevation.tif'
filename2 = 'friction.tif'
filename3 = 'destination.shp'
filename4 = 'walked.tif'

elevation = QgsRasterLayer(path + filename1, 'elevation')
friction = QgsRasterLayer(path + filename2, 'friction')
destination = QgsVectorLayer(path + filename3, 'destination',"ogr")

extent = elevation.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()

min_area = 0.000100
#pixelsize = 0.000000
pixelsize = 0.100000

#processing.runalg('grass:r.walk', elevation, friction, destination, "0", "100", "", "0.72,6.0,1.9998,-1.9998", "1.0", "-0.2125",True,True, True, "%f,%f,%f,%f"% (xmin, xmax, ymin, ymax), pixelsize, "-1", min_area, path + filename4)
processing.runalg('grass:r.walk', elevation, friction, destination, "0", "100", "", "0.72,6.0,1.9998,-1.9998", "1.0", "-0.2125",True,True, False, "%f,%f,%f,%f"% (xmin, xmax, ymin, ymax), pixelsize, "-1", min_area, path + filename4)

After an execution without getting a result raster, the console log shows problematic rows:

    C:\PROGRA~1\QGIS2~1.14\bin>r.external -r input="d:\Works\_EvacuationSimulation\_raster\walk\unit-elevation.tif" band=1 output=tmp1482592256518 --overwrite -o 

    ERROR: r.external: Sorry, <r> is not a valid flag

    C:\PROGRA~1\QGIS2~1.14\bin>r.external -r input="d:\Works\_EvacuationSimulation\_raster\walk\friction-cost.tif" band=1 output=tmp1482592256519 --overwrite -o 

    ERROR: r.external: Sorry, <r> is not a valid flag

    C:\PROGRA~1\QGIS2~1.14\bin>r.walk  elevation="tmp1482592256518" friction="tmp1482592256519" start_points="tmp14825922565110" max_cost="0" percent_memory="100" walk_coeff="0.72,6.0,1.9998,-1.9998" lambda="1.0" slope_factor="-0.2125" -k -n output=outpute943ea890dd94b879185c7266a98f4c3 --overwrite 
    GRASS_INFO_ERROR(4668,5): Raster map <tmp1482592256518> not found

    GRASS_INFO_ERROR(5548,1): Raster map <outpute943ea890dd94b879185c7266a98f4c3> not found

Probably the problem comes from the built-in r.external function of the r.walk script, which uses a no longer exist '-r' flag.

Can you help to solve this?


Finally solved by changing the GRASS folder in Processing options to an older version:

C:\Program Files\QGIS 2.14\apps\grass\grass-6.4.3

(from C:\Program Files\QGIS 2.14\apps\grass\grass-7.0.5)


Try writing this:

path= 'd:/Works/_Simulation/_raster/walk/'

instead of what you have provided or eliminating the - characters from your filenames.

  • I edited the code as you mentioned, but unfortunately happened the same :/ The vector layer have been read perfectly by the way, the problem can be still with the raster. – pnz Dec 24 '16 at 17:54
  • Do you have any cell in the raster layers with NULL values? – mgri Dec 24 '16 at 18:32
  • I uploaded the necessary layers here: github.com/ewirth/evacuation/tree/master/data I haven't mentioned that the process work in grass gui, but I would like to automate it with these python code. The elevation layer has only 0 and 1 values. The friction layer consist 0 and 'nan' cells as well. – pnz Dec 24 '16 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.