4

I am working under Qgis 2.16.0 and i am trying to make a script using the grass module r.water.oulet. This module has 5 parameters :

1 - Name of input raster 2 - coordinates of outlet point (x,y) 3 - area of the Grass region (xmin, xmax, ymin, ymax) 4 - Celle size of Grass Region 5- Output file

When i use the module in Qgis I don't need to set the area of Grass region. But if d'ont set it in python command :

processing.runalg('grass:r.water.outlet', "D:\Developpement\Debits_cartes_alea\Donnees_test\flow_direction.tif",936400.018,6432568.853,None,0.0,"D:\Developpement\Debits_cartes_alea\Donnees_test\1sortie.tif")

I have this error message : "Error: Wrong parameter value: None"

So I try to set the required coordinates like this :

processing.runalg('grass:r.water.outlet', "D:\Developpement\Debits_cartes_alea\Donnees_test\flow_direction.tif",936400.018,6432568.853,['933963.950608,940746.141038,6431270.66542,6434790.6058'],0.0,"D:\Developpement\Debits_cartes_alea\Donnees_test\1sortie.tif")

Then I have this error message : "Error: Wrong parameter value: ['933963.950608,940746.141038,6431270.66542,6434790.6058']"

Does that come from the syntax or is ther the problem with the values (note that I try with the same values in module and it's work !)

Joseph
  • 75,746
  • 7
  • 171
  • 282
Panvjim0
  • 265
  • 2
  • 10
  • did you try without the brackets []? And for None with 'None' ? – Victor Sep 16 '16 at 15:55
  • Yes I try both. If I don't use bracket [] then the error is that I don't give the good number of parameters. If I try 'None' the problem is the same than with None. – Panvjim0 Sep 16 '16 at 16:02
  • I am guessing sorry, but shouldn't you have '936400.018,6432568.853' for third parameter? – Victor Sep 16 '16 at 16:06
  • I think there is no problem with the parameters values because when I try with the same values using the module it works well. – Panvjim0 Sep 19 '16 at 06:22

1 Answers1

5

Usually when I run processes, I define the extent instead of leaving it blank (which often results in errors like you have shown). So you could use something like the following:

# Define input and output paths
path = "D:/Developpement/Debits_cartes_alea/Donnees_test/flow_direction.tif"
output = "D:/Developpement/Debits_cartes_alea/Donnees_test/1sortie.tif"

# Get raster data
fileInfo = QFileInfo(path)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(fileName, baseName)

# Define the minimum extent of the region
extent = rlayer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()

import processing
processing.runalg('grass:r.water.outlet', path,
    936400.018,6432568.853,
    "%f,%f,%f,%f"% (xmin, xmax, ymin, ymax),
    0.0,
    output)
Joseph
  • 75,746
  • 7
  • 171
  • 282