6

I use the GRASS GIS extensions for QGIS (QGIS version 2.12.3 with GRASS 6.4) and I have a problem with the r.drain algorithm: I simply cannot make it work with a given starting point as a vector point.

To put it simple, here is what I try to achieve:

• Insert a cost-raster

• Insert a vector point

• Calculate least cost path

I managed to get it to run when I enter the coordinates for the starting point manually, but since I want to use r.drain in the Model Builder of QGIS, that’s not the solution I am looking for.

Here is the log message:

Algorithmus r.drain - Traces a flow through an elevation model on a raster map. startet...
g.proj -c proj4="+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 +units=m +no_defs"
r.external -r input="C:\Users\M73C7~1.THY\AppData\Local\Temp\processing2dc0bf84d6904a2e98cf88aa7c96f01b\65449bc0c78d4f88bd9ccb81f73dd7db\outputALGGRASSR.COST1.tif" band=1 output=tmp14538092333818 --overwrite -o
g.region n=5728838.9502 s=5642436.07274 e=3563614.80147 w=3517244.6193 res=30
r.drain input="tmp14538092333818" coordinate="0,0" vector_points="T:/End_Netzpunkt.shp" output=output31af3facd469466da5d085a4022c5830 --overwrite
g.region rast=output31af3facd469466da5d085a4022c5830
r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW" input=output31af3facd469466da5d085a4022c5830 output="C:\Users\M73C7~1.THY\AppData\Local\Temp\processing2dc0bf84d6904a2e98cf88aa7c96f01b\87ddeef3905446ef8f464853f27a795f\output.tif"

GRASS commands output:

C:\PROGRA~1\QGISLY~1\bin>set HOME=C:\Users\
C:\PROGRA~1\QGISLY~1\bin>set GISRC=C:\Users\.qgis2\\processing\processing.gisrc 
C:\PROGRA~1\QGISLY~1\bin>set GRASS_SH=C:/PROGRA~1/QGISLY~1/apps\msys\bin\sh.exe 
C:\PROGRA~1\QGISLY~1\bin>set PATH=C:/PROGRA~1/QGISLY~1/apps\msys\bin;C:/PROGRA~1/QGISLY~1/apps\msys\lib;C:\PROGRA~1\QGISLY~1\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGISLY~1\apps\qgis\bin;C:\PROGRA~1\QGISLY~1\apps\grass\grass-6.4.3\lib;C:\PROGRA~1\QGISLY~1\apps\grass\grass-6.4.3\bin;C:\PROGRA~1\QGISLY~1\apps\msys\bin;C:\PROGRA~1\QGISLY~1\apps\Python27\Scripts;C:\PROGRA~1\QGISLY~1\bin;C:\Windows\system32;C:\Windows;C:\Windows\WBem;C:\PROGRA~1\QGISLY~1\apps\msys\bin 
C:\PROGRA~1\QGISLY~1\bin>set WINGISBASE=C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3  
C:\PROGRA~1\QGISLY~1\bin>set GISBASE=C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3 
C:\PROGRA~1\QGISLY~1\bin>set GRASS_PROJSHARE=C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\share\proj 
C:\PROGRA~1\QGISLY~1\bin>set GRASS_MESSAGE_FORMAT=gui 
C:\PROGRA~1\QGISLY~1\bin>if "" == "" set PATH=C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\bin;C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\lib;C:/PROGRA~1/QGISLY~1/apps\msys\bin;C:/PROGRA~1/QGISLY~1/apps\msys\lib;C:\PROGRA~1\QGISLY~1\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGISLY~1\apps\qgis\bin;C:\PROGRA~1\QGISLY~1\apps\grass\grass-6.4.3\lib;C:\PROGRA~1\QGISLY~1\apps\grass\grass-6.4.3\bin;C:\PROGRA~1\QGISLY~1\apps\msys\bin;C:\PROGRA~1\QGISLY~1\apps\Python27\Scripts;C:\PROGRA~1\QGISLY~1\bin;C:\Windows\system32;C:\Windows;C:\Windows\WBem;C:\PROGRA~1\QGISLY~1\apps\msys\bin 
C:\PROGRA~1\QGISLY~1\bin>if not "" == "" set PATH=C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\bin;C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\lib;;C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\bin;C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\lib;C:/PROGRA~1/QGISLY~1/apps\msys\bin;C:/PROGRA~1/QGISLY~1/apps\msys\lib;C:\PROGRA~1\QGISLY~1\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGISLY~1\apps\qgis\bin;C:\PROGRA~1\QGISLY~1\apps\grass\grass-6.4.3\lib;C:\PROGRA~1\QGISLY~1\apps\grass\grass-6.4.3\bin;C:\PROGRA~1\QGISLY~1\apps\msys\bin;C:\PROGRA~1\QGISLY~1\apps\Python27\Scripts;C:\PROGRA~1\QGISLY~1\bin;C:\Windows\system32;C:\Windows;C:\Windows\WBem;C:\PROGRA~1\QGISLY~1\apps\msys\bin 
C:\PROGRA~1\QGISLY~1\bin>set GRASS_VERSION=6.4.0
C:\PROGRA~1\QGISLY~1\bin>if not "" == "" goto langset 
C:\PROGRA~1\QGISLY~1\bin>FOR /F "usebackq delims==" %i IN (`"C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\etc\winlocale"`) DO @set LANG=%i 
C:\PROGRA~1\QGISLY~1\bin>set PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY 
C:\PROGRA~1\QGISLY~1\bin>set PYTHONPATH=;C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\etc\python;C:/PROGRA~1/QGISLY~1/apps\grass\grass-6.4.3\etc\wxpython\n 
C:\PROGRA~1\QGISLY~1\bin>g.gisenv.exe set="MAPSET=PERMANENT" 
C:\PROGRA~1\QGISLY~1\bin>g.gisenv.exe set="LOCATION=temp_location" 
C:\PROGRA~1\QGISLY~1\bin>g.gisenv.exe set="LOCATION_NAME=temp_location" 
C:\PROGRA~1\QGISLY~1\bin>g.gisenv.exe set="GISDBASE=C:\Users\M73C7~1.THY\AppData\Local\Temp\processing2dc0bf84d6904a2e98cf88aa7c96f01b\grassdata" 
C:\PROGRA~1\QGISLY~1\bin>g.gisenv.exe set="GRASS_GUI=text" 
C:\PROGRA~1\QGISLY~1\bin>g.proj -c proj4="+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 +units=m +no_defs" 
GRASS_INFO_MESSAGE(3236,1): Die Standard Region wurde auf die neue Projektion aktualisiert. Wenn Sie aber mehrere Mapsets haben, sollten Sie `g.region -d` in jedem ausführen, um die Einstellungen von der Standardregion zu übernehmen. 
GRASS_INFO_END(3236,1) 
GRASS_INFO_MESSAGE(3236,2): Projektionsinformationen aktualisiert 
GRASS_INFO_END(3236,2) 
C:\PROGRA~1\QGISLY~1\bin>r.external -r input="C:\Users\M73C7~1.THY\AppData\Local\Temp\processing2dc0bf84d6904a2e98cf88aa7c96f01b\65449bc0c78d4f88bd9ccb81f73dd7db\outputALGGRASSR.COST1.tif" band=1 output=tmp14538092333818 --overwrite -o 
GRASS_INFO_WARNING(972,1): Übersteuere die Überprüfung der Projektion. 
GRASS_INFO_END(972,1) 
GRASS_INFO_MESSAGE(972,2): Importing band 1 of 1... 
GRASS_INFO_END(972,2) 
GRASS_INFO_MESSAGE(972,3): Link zur Rasterkarte erzeugt 
GRASS_INFO_END(972,3) 
C:\PROGRA~1\QGISLY~1\bin>g.region n=5728838.9502 s=5642436.07274 e=3563614.80147 w=3517244.6193 res=30 
C:\PROGRA~1\QGISLY~1\bin>r.drain input="tmp14538092333818" coordinate="0,0" vector_points="T:/End_Netzpunkt.shp" output=output31af3facd469466da5d085a4022c5830 --overwrite 
GRASS_INFO_MESSAGE(3472,1): Oberflächen-/Hydrologischer-Abfluß ausgewählt 
GRASS_INFO_END(3472,1) 
GRASS_INFO_WARNING(3472,2): Startpunkt 1 ist außerhalb der aktuellen Region. 
GRASS_INFO_END(3472,2) 
Ungültiger Dateiname. Das Zeichen ist nicht erlaubt. 
GRASS_INFO_ERROR(3472,3): Vektorkarte nicht gefunden. 
GRASS_INFO_END(3472,3) 
C:\PROGRA~1\QGISLY~1\bin>g.region rast=output31af3facd469466da5d085a4022c5830 
GRASS_INFO_ERROR(3560,1): Rasterkarte konnte nicht gefunden werden. 
GRASS_INFO_END(3560,1) 
C:\PROGRA~1\QGISLY~1\bin>r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW" input=output31af3facd469466da5d085a4022c5830 output="C:\Users\M73C7~1.THY\AppData\Local\Temp\processing2dc0bf84d6904a2e98cf88aa7c96f01b\87ddeef3905446ef8f464853f27a795f\output.tif" 
GRASS_INFO_ERROR(1796,1): Rasterkarte oder Gruppe nicht gefunden. 
GRASS_INFO_END(1796,1) 
C:\PROGRA~1\QGISLY~1\bin>exit 
Converting outputs
Lade Ergebnis Layer

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

2

I tried out the r.drain algorithm in my QGIS (version 2.12, GRASS 6.4) with the raster dem and point (in blue) of below image.

enter image description here

After running the r.drain grass module with successfully finish.

enter image description here

I copied and pasted the complete r.drain command at the GRASS shell; with another name for the output raster.

r.drain input=utah_demUTM2@javier output=out_raster "coordinate=366466.04693, 4461604.75446"

After running the command in this way, I also had a successfully (and the same) result:

enter image description here

If you want other parameters at your r.drain command, you have a detailed explanation in the Module Manual:

enter image description here

  • First, thank you xunilk for your answer! But the thing I try to achieve is getting r.drain to run without entering the coordinates of the starting point manually, but to insert a shapefile containing a starting point and then let it run with that point. I hope you get my “point” ;) – Miron Jan 27 '16 at 9:15
  • 1
    I understood. So, I think that you need grass.script with python for retrieving the shapefile point coordinates. – xunilk Jan 27 '16 at 9:52
  • Hm, do you or anyone here has any suggestion how I might do that? I'm not really much into scripting I have to admit...Thanks anyway! – Miron Feb 2 '16 at 8:31

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.