Sunday, 11 September 2016

qgis plugins - PyQGIS Processing: "memory: not found"


I try to run a QGIS plugin in QGIS 3.4 that uses processing to execute algorithms in a row:


    params_snap = {
'input' : input,
'type' : 1,
'tool' : 1,
'threshold' : 0.000095,

'output': 'memory:',
'error' : error,
'GRASS_OUTPUT_TYPE_PARAMETER' : 2
}

snap = processing.runAndLoadResults('grass7:v.clean', params_snap)

params_break = {
'input': snap['output'],
'type': 1,

'tool': 0,
'threshold': 0,
'output': output,
'error': error,
'GRASS_OUTPUT_TYPE_PARAMETER': 2
}

processing.runAndLoadResults('grass7:v.clean', params_break)

First the v.clean snap algorithm runs. The result is saved in a temporary output layer. This algorithm work without any problems. Afterwards I try to run v.clean break and the input should be the temporarily saved output layer of the first algorithm. But I get the error: Could not load source layer for input: memory: not found.



If I use a filepath instead of 'memory:' in the first output everything works fine and the second algorithm can access the first algorithms output. So I assume that the problem is the 'memory:' statement, but all the sources I found tell to use it.


Edit:


I checked the temporary folder (C:\Users\USER\AppData\Local\Temp\processing_83c42fa467d2461eb67590c719fc22aa\grassdata\temp_location\PERMANENT\vector) and the layer gets successfully created when I run the code. But since it is not located directly in the path C:\Users\USER\AppData\Local\Temp\ I wonder if the path the temporary files are created in is the right one?



Answer



The grass provider does not support QGIS memory layers, so you'll need to give it a path to a real location it can store the temporary result as.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...