I'm trying to do a Least Cost Path analysis, following upon these suggestions.

I got a DEM, created a slope layer from it, then used r.cost (Processing Toolbox) to create a cost surface. But when I run the r.drain module, I get an error and no file created. Here's the log with the error message:

A iniciar o algoritmo r.drain - Traces a flow through an elevation model on a raster map.... g.proj -c proj4="+proj=utm +zone=22 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" r.external input="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path/Cumulative-cost.tif" band=1 output=tmp14908042929517 --overwrite -o v.in.ogr min_area=0.0001 snap=-1 input="C.../Exercicios em teste/Novos exercicios/Least Cost Path" layer=Pontos-Alvo output=tmp14908042929518 --overwrite -o g.region -a n=9840380.0 s=9840130.0 e=785141.0 w=784667.0 res=1.0 r.drain input=tmp14908042929517 start_coordinates="(0,0)" start_points=tmp14908042929518 -c -a -n output=output41993ef1fbf245b780c12dd73c1c4c96 --overwrite g.region raster=output41993ef1fbf245b780c12dd73c1c4c96 r.out.gdal --overwrite -c createopt="TFW=YES,COMPRESS=LZW" input=output41993ef1fbf245b780c12dd73c1c4c96 output="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path/LeastCostPath.tif"

C:\PROGRA~1\QGIS2~1.14\bin>set HOME=C:\Users\

C:\PROGRA~1\QGIS2~1.14\bin>set GISRC=C:\Users....qgis2\processing\processing.gisrc7

C:\PROGRA~1\QGIS2~1.14\bin>set WINGISBASE=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0

C:\PROGRA~1\QGIS2~1.14\bin>set GISBASE=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0

C:\PROGRA~1\QGIS2~1.14\bin>set GRASS_PROJSHARE=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\share\proj


C:\PROGRA~1\QGIS2~1.14\bin>if "" == "" set PATH=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\bin;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\lib;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\Shapely-1.2.18-py2.7-win-amd64.egg\shapely\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGIS2~1.14\apps\qgis-ltr\bin;C:\PROGRA~1\QGIS2~1.14\apps\Python27\Scripts;C:\PROGRA~1\QGIS2~1.14\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\WBem

C:\PROGRA~1\QGIS2~1.14\bin>if not "" == "" set PATH=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\bin;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\lib;;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\bin;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\lib;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\Shapely-1.2.18-py2.7-win-amd64.egg\shapely\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGIS2~1.14\apps\qgis-ltr\bin;C:\PROGRA~1\QGIS2~1.14\apps\Python27\Scripts;C:\PROGRA~1\QGIS2~1.14\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\WBem

C:\PROGRA~1\QGIS2~1.14\bin>set GRASS_VERSION=7.0.0

C:\PROGRA~1\QGIS2~1.14\bin>if not "" == "" goto langset

C:\PROGRA~1\QGIS2~1.14\bin>FOR /F "usebackq delims==" %i IN ("C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\etc\winlocale") DO @set LANG=%i


C:\PROGRA~1\QGIS2~1.14\bin>set PYTHONPATH=;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\etc\python;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\etc\wxpython\n

C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="MAPSET=PERMANENT"

C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="LOCATION=temp_location"

C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="LOCATION_NAME=temp_location"

C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="GISDBASE=C:\Users...\AppData\Local\Temp\processing961f3d92f1074413bf58edae90f70b98\grassdata"

C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="GRASS_GUI=text"

C:\PROGRA~1\QGIS2~1.14\bin>g.proj -c proj4="+proj=utm +zone=22 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" Default region was updated to the new projection, but if you have multiple mapsets g.region -d should be run in each to update the region from the default Projection information updated

C:\PROGRA~1\QGIS2~1.14\bin>r.external input="C:/Users/.../Exercicios em teste/Novos exercicios/Least Cost Path/Cumulative-cost.tif" band=1 output=tmp14908042929517 --overwrite -o ATENÇÃO: Over-riding projection check Reading band 1 of 1... r.external completo. Link to raster map created.

C:\PROGRA~1\QGIS2~1.14\bin>v.in.ogr min_area=0.0001 snap=-1 input="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path" layer=Pontos-Alvo output=tmp14908042929518 --overwrite -o Over-riding projection check Check if OGR layer contains polygons... 0..50..100 Importing 2 features (OGR layer )... 0..50..100 ----------------------------------------------------- A construir topologia para mapa vectorial ... Registando primitivas...

2 primitives registered 2 vertices registered A construir áreas... 0..50..100 0 areas built 0 isles built A anexar ilhas... A anexar centróides... 50..100 Número de nós: 0 Número de primitivos: 2 Número de pontos: 2 Número de linhas: 0 Número de fronteiras: 0 Número de centróides: 0 Número de áreas: 0 Número de ilhas: 0

C:\PROGRA~1\QGIS2~1.14\bin>g.region -a n=9840380.0 s=9840130.0 e=785141.0 w=784667.0 res=1.0

C:\PROGRA~1\QGIS2~1.14\bin>r.drain input=tmp14908042929517 start_coordinates="(0,0)" start_points=tmp14908042929518 -c -a -n output=output41993ef1fbf245b780c12dd73c1c4c96 --overwrite

Description: Traces a flow through an elevation model or cost surface on a raster map.

Keywords: raster, hydrology, cost surface

Usage: r.drain [-cand] input=name [direction=name] output=name [drain=name] [start_coordinates=east,north] [start_points=name[,name,...]] [--overwrite] [--help] [--verbose] [--quiet] [--ui]

Flags: -c Copia valores da célula de entrada -a Acumula valores da entrada ao longo do caminho -n Conta número de células ao longo do caminho -d The input raster map is a cost surface (direction surface must also be specified) --o Permitir que os ficheiros de saída reescrevam os ficheiros existentes --h Print usage summary --v Saída do módulo verbosa --q Saída do módulo quiet --qq Super quiet module output --ui Force launching GUI dialog

Parameters: input Name of input elevation or cost surface raster map direction Name of input movement direction map associated with the cost surface output Nome do mapa raster de saída drain Name for output drain vector map Recommended for cost surface made using knight's move start_coordinates Coordinates of starting point(s) (E,N) start_points Name of starting vector points map(s)

ERROR: Missing value for parameter

C:\PROGRA~1\QGIS2~1.14\bin>g.region raster=output41993ef1fbf245b780c12dd73c1c4c96 ERRO:Raster map not found

C:\PROGRA~1\QGIS2~1.14\bin>r.out.gdal --overwrite -c createopt="TFW=YES,COMPRESS=LZW" input=output41993ef1fbf245b780c12dd73c1c4c96 output="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path/LeastCostPath.tif" ERRO:Raster map or group not found

C:\PROGRA~1\QGIS2~1.14\bin>exit Converting outputs Carregando as camadas resultantes

The following layers were not correctly generated. • Least cost path You can check the log messages to find more information about the execution of the algorithm

I can't figure out what am I doing wrong.

Can someone help with this issue?

  • 1
    Did you run the module from Processing or from the Python Console? In both cases, could you please edit the question by attaching an image with a screenshot of the input dialog (or the code snippet)?
    – mgri
    Mar 30 '17 at 7:28
  • Hi, I used Processing (not Python-able enough for the time being). I may manage to get the time to replicate the process tomorrow and get you that image. Anyway, I managed earlier today to create a LCP, by using the SAGA module for the last step (r.drain). Would the results be similar to the process I was trying before?
    – TTome
    Mar 31 '17 at 0:17
  • I don't know this modules. However, if you add a screenshot of what you inserted as input parameters for r.drain, I may try to help (every detail you will add for the description of the issue would be welcomed).
    – mgri
    Mar 31 '17 at 6:07
  • 1
    I see there start_coordinates="(0,0)" for the r.drain call, this will hardly work :-)
    – markusN
    Mar 31 '17 at 12:34
  • Could you please explain what you mean, markus?
    – TTome
    Apr 1 '17 at 14:52

As @markusN has pointed out, the message start_coordinates="(0,0)" reported that you have left Map coordinates of the starting point(s) untouched, like the image below. Using QGIS2.14 we have to be very careful, as r.drain shows (0,0) by default.

enter image description here

There are two issues with (0,0) because:

  • E,N coordinates have to be given without brackets
  • The point has to be within extent of Cost raster (I bet 0,0 is outside of your raster.)

We can expect failures by running r.drain :

  • If E,N coordinates are given with brackets (), r.drain fails with error message as in OP.
  • If E,N coordinates are 0,0 (outside of the raster area), r.drain still fails with error message as in OP.
  • If the given coordinates are outside of the Cost Surface has values (but still in the raster area), it finishes calculation without error and returns Least cost path layer. Of course, the layer is blank.

Please see below how it works when the E,N coordinates are given as 550000,5700000 (which is red point at the LR corner). In this example an optional Vector layer (green point) was also added.

enter image description here

A good news is that recent QGIS2.18 changed its UI to show 0.0,0.0 without brackets.

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.