Why my python script of r.watershed has no output?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why my python script of r.watershed has no output?

Heinz Chen

As title, I want to use r.watershed module, and here's my python script in pyscripter,

import os
import sys

#set up GRASS environment variables
sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))
import grass.script as g
import grass.script.setup as gsetup
gisbase = os.environ['GISBASE']
gisdb = 'C:\Users\Heinz\Documents\grassdata'
location = 'newLocation'
mapset = 'TC'
gsetup.init(gisbase, gisdb, location, mapset)

#run r.watershed module
#set thresh = 5000
g.run_command('r.watershed', elevation = 'hc', threshold = 5000, accumulation = 'acc1', drainge = 'dra1', basin = 'bas1', stream = 'str1', half = 'hbas1', visual = 'vis1')
print g.read_command('g.list', _type = 'rast')
the output has generate no new raster data, and if I change the input parameter 'half', an error will occur.
Can't GRASS just take the position of parameters, no matter what their name is, to execute the module?

For more detail, please visit Why my python script of r.watershed has no output?, thank you.

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: Why my python script of r.watershed has no output?

wenzeslaus
I answered your question at


and added an example with full module call:


gcore.run_command('r.watershed', elevation='elev_lid792_1m', drainage='elev_lid_drainage', half='elev_lid_half_basin', accumulation='elev_lid_accumulation', basin='elev_lid_basin', stream='elev_lid_stream', visual='elev_lid_visual', length='elev_lid_length_slope', slope='elev_lid_slope_steepness', threshold=10)

I suppose that the error you are getting is:

Sorry, <drainge> is not a valid parameter
(followed by a full module help)

Your command in this email has an typo: it should be `drainage` not `drainge`. As MarkusN pointed out in the other answer at SE.

This command works for me if I change the elevation map to something I have:

gcore.run_command('r.watershed', elevation = 'hc', threshold = 5000, accumulation = 'acc1', drainage = 'dra1', basin = 'bas1', stream = 'str1', half = 'hbas1', visual = 'vis1')

Best,
Vaclav


On Mon, Mar 31, 2014 at 12:56 PM, Heinz Chen <[hidden email]> wrote:

As title, I want to use r.watershed module, and here's my python script in pyscripter,


import os
import sys

#set up GRASS environment variables
sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))
import grass.script as g
import grass.script.setup as gsetup
gisbase = os.environ['GISBASE']
gisdb = 'C:\Users\Heinz\Documents\grassdata'
location = 'newLocation'
mapset = 'TC'
gsetup.init(gisbase, gisdb, location, mapset)

#run r.watershed module
#set thresh = 5000
g.run_command('r.watershed', elevation = 'hc', threshold = 5000, accumulation = 'acc1', drainge = 'dra1', basin = 'bas1', stream = 'str1', half = 'hbas1', visual = 'vis1')
print g.read_command('g.list', _type = 'rast')
the output has generate no new raster data, and if I change the input parameter 'half', an error will occur.
Can't GRASS just take the position of parameters, no matter what their name is, to execute the module?

For more detail, please visit Why my python script of r.watershed has no output?, thank you.

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user


_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user