[Qgis-user] How do I pass parameters to grass7 algorithms with Processing.run?
Stephen
posting at vodacomm.ca
Mon May 14 02:30:17 PDT 2018
Hi Nyall,
I'm revisiting this problem now after a month. Thanks for your help on this.
On 11.04.2018 02:03, Nyall Dawson wrote:
>> After correcting the statement to the following:
>>
>>> file_grid_r = QgsRasterLayer()
>>> processing.run("grass7:v.to.rast", {'input': grid_v, 'type': 0, 'use': 1,
>>> 'GRASS_REGION_PARAMETER': extent,
>>> 'output': file_grid_r,
>>> 'GRASS_REGION_CELLSIZE_PARAMETER':
>>> 0.008333,
>>> 'GRASS_SNAP_TOLERANCE_PARAMETER': -1,
>>> 'GRASS_MIN_AREA_PARAMETER': 0.000100},
>>> feedback=QgsProcessingFeedback())
>>
>>
>> I get the message
>>
>>> Unable to execute algorithm
>>> Incorrect parameter value for output
>
> The OUTPUT parameter should be set to the path to save the result,
> e.g. 'd:\blahblah.tif":
>
> processing.run("grass7:v.to.rast", {'input': grid_v, 'type': 0, 'use': 1,
> 'GRASS_REGION_PARAMETER': extent,
> 'output': 'd:\blah.tif',
> 'GRASS_REGION_CELLSIZE_PARAMETER':
> 0.008333,
> 'GRASS_SNAP_TOLERANCE_PARAMETER': -1,
> 'GRASS_MIN_AREA_PARAMETER': 0.000100},
> feedback=QgsProcessingFeedback())
>
> processing.run will return a dict a results, and inside that you'll
> automatically have a QgsRasterLayer loaded corresponding to this
> output.
>
> E.g.
>
> params = { ....., 'OUTPUT': 'd:\blah.tif' }
> results = processing.run('grass7:v.to.rast', params, feedback )
> my_raster_layer = results['OUTPUT']
> assert my_raster_layer.isValid()
>
> Here my_raster_layer will be a QgsRasterLayer, ready for further
> processing or adding to the project for visualisation.
>
> I'm pondering whether we should automatically set output locations to
> temporary files if they aren't specified. E.g. if you don't set OUTPUT
> to 'd:\blah.tif', it'll fill it in automatically with a .tif file in
> your temp folder...
>
> Nyall
Automatically setting output paths to temporary files would be a
sensible convenience, I think.
In any event, I used processing.tools.system.getTempFilename() to set a
filename and that gets me past the 'Incorrect parameter value for
output' error.
However, I am still getting "Unable to execute algorithm".
In AlgorithmExecutor, line 55:
results, ok = alg.run(parameters, context, feedback)
returns ({}, False)
parameters contains:
{'GRASS_REGION_CELLSIZE_PARAMETER': 0.008333, 'use': 1,
'GRASS_REGION_PARAMETER':
'33.91415594546105,41.91384412832699,-4.679722671256611,5.467319665842772',
'input': <qgis._core.QgsVectorLayer object at 0x7fdbbd02bc18>,
'GRASS_MIN_AREA_PARAMETER': 0.0001, 'GRASS_SNAP_TOLERANCE_PARAMETER':
-1, 'type': 0, 'output':
'/tmp/processing_da49d2e8c1bd4e249d1a5c6d42680149/5af9540a0b2212'}
context contains:
<qgis._core.QgsProcessingContext object at 0x7fdbbd04e3a8>
and feedback contains:
<qgis._core.QgsProcessingFeedback object at 0x7fdbbd02bee8>
Without a useful error message, it's very difficult to troubleshoot this
on my own.
Do you have any idea what might be wrong here?
Thanks
Stephen Bosch
More information about the Qgis-user
mailing list