3

Using Qgis 2.14.12 and PyQGIS, I get an error message when executing the following:

processing.runalg('grass7:v.surf.idw', layer, 18, 2.0, 'p', True, "%f, %f, %f ,%f"%(1.635, 1.813, 50.896,  51.0205), 0.005, -1, 0.001, "e://out.tif")

The output from

layer.isValid()

is True, but I get this error (warning) in the Python Console :

C:\PROGRA~1\QGIS2~1.14\bin>g.region n= 51.020500 s= 50.896000 e= 1.813000 w=1.635000 res=0.005                  
   Sorry, <51.020500> isn't a valid option                  
   Sorry, <50.896000> isn't a valid option                  
   Sorry, <1.813000> isn't a valid option

This results in a 1 km raster at lat/lon 0/0.

However, when I launch the function from the QGIS toolbox, the output is fine.

I've tried both with GRASS 6 & 7.

Any ideas?

1 Answer 1

3

The syntax seems to be correct, but you need to remove the blank space when specifying the extent. Try replacing:

"%f, %f, %f ,%f"%(1.635, 1.813, 50.896,  51.0205)

with:

"%f,%f,%f,%f" %(1.635, 1.813, 50.896,  51.0205)

In this way, you will write it as a string.

The working command should be:

processing.runalg('grass7:v.surf.idw', layer, 18, 2.0, 'p', True, "%f,%f,%f,%f"%(1.635, 1.813, 50.896,  51.0205), 0.005, -1, 0.001, "e://out.tif") 
14
  • I tried that prior to using %f, but still giving me that error. What i don't get is that it works fine though the toolbox. Commented Mar 28, 2017 at 13:15
  • @julsbreakdown Why did you specify 0.005 as output size of the cell? a 5 mm resolution raster seems is not so common. Furthermore, 0.001 should be 0.0001 if left as default value. What about using 0 instead of 0.005 and 0.0001 instead of 0.001?
    – mgri
    Commented Mar 28, 2017 at 13:22
  • for the default value 0.001 that was a typo, for the resolution i tried giving a aberrant value to see if it made a difference. But even with default values a still get the error/warning message Commented Mar 28, 2017 at 13:44
  • 1
    Run the algorithm from the Processing Toolbox and then go to Processing > History, open the ALGORITHM folder (it displays all the operations you ran from Processing). Try to find the differences with your script: is it equals to yours?
    – mgri
    Commented Mar 28, 2017 at 14:08
  • 1
    I think it should be useful to others if I edit my answer including the final solution instead of the first one I provided, so you may accept it for helping other future readers.
    – mgri
    Commented Mar 28, 2017 at 14:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.