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_test1円sortie.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_test1円sortie.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
76.7k8 gold badges173 silver badges286 bronze badges
asked Sep 16, 2016 at 15:42
4
  • did you try without the brackets []? And for None with 'None' ? Commented Sep 16, 2016 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. Commented Sep 16, 2016 at 16:02
  • I am guessing sorry, but shouldn't you have '936400.018,6432568.853' for third parameter? Commented Sep 16, 2016 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. Commented Sep 19, 2016 at 6:22

1 Answer 1

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)
answered Sep 19, 2016 at 11:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.