1

I am writing a python plugin for QGIS and I need to use an inbuilt tool "Distance to nearest hub (line to hub)" in the QGIS processing toolbox. The following line is supposed to give me the desired output as a scratch layer.

processing.run("qgis:distancetonearesthublinetohub", {'INPUT':base_layer,'HUBS':destination_layer, 'FIELD':id,'UNIT':measuring_unit,'OUTPUT':'memory'})

However, I get the following error when using this command.

Could not create layer memory.gpkg: Creation of data source failed (OGR error: sqlite3_open(memory.gpkg) failed: unable to open database file)

But still, this works quite fine when I replace the last argument "memory" with a xxxxx.shp filepath and the output gets stored in a shapefile. And this output looks as expected when this xxxxx.shp is loaded into the project. So, the problem is, the output cannot be stored as a scratch layer.

I have looked up these forums and couldn't find an answer that really fixed this issue.

3
  • 2
    Try 'TEMPORARY_OUTPUT' instead of 'memory'. If you want to load the result use processing.runAndLoadResults instead of processing.run
    – Ben W
    Dec 13 '21 at 4:36
  • @BenW Thank you very much for your swift response! This is exactly what I was after. Couldn't find this in the documentation for some reason. Thanks again!
    – Ravindu
    Dec 13 '21 at 5:31
  • No problem, you are very welcome:-)
    – Ben W
    Dec 13 '21 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.