0

So whenever I do something like buffer in QGIS with Vecotr>>Geoprocessing Tools>>Buffer... the source output I get for my temporary file looks like this:

enter image description here

That works fine if I'm doing more QGIS actions, but then I need to use r.patch and for it to work I need to put actual paths as inputs(or if I don't tell me how to make it accept the source above).

If I do it manually, it knows the path and if I go in the processing history I can see he used: C:/Users/Phil/AppData/Local/Temp/processing_534fdc910b13414bbab4810d36304212/15b103f620a74a189c2370a8abee2ba0/output.tif

But I have no idea how to go get that path. Right now this is how my buffer looks:

processing.runAndLoadResults("native:buffer", \
{'INPUT':tmp_riv_ponc_Intersect_Clipped,\
'DISTANCE':1.5,\
'SEGMENTS':5,\
'END_CAP_STYLE':0,\
'JOIN_STYLE':0,\
'MITER_LIMIT':2,\
'DISSOLVE':False,\
'OUTPUT':'TEMPORARY_OUTPUT'})

QgsProject.instance().mapLayersByName('Buffered')[0].setName('Riv_Ponc_Intersect_Buffered')
tmp_riv_ponc_Intersect_Buffered = QgsProject.instance().mapLayersByName('Riv_Ponc_Intersect_Buffered')[0].source()

And the tmp_riv_ponc_Intersect_Buffered gives the source of the picture shown above. I also tried to use the same line but instead of source I put ".dataProvider().dataSourceUri()" but it gave me pretty much the same thing except a couple of lines from the Source were missing.

I also tried to put "memory:" instead of TEMPORARY_OUTPUT but didn't change anything. I tried to do

output_path = processing.runAndLoadResults(...
{'OUTPUT': 'output_22c6c1b4_1c03_44c8_92dd_3dffc7a6a0d8'} #Output = "memory:"
{'OUTPUT': 'Clipped_5b605e64_620d_4ac4_a1b1_64a329f6c2b5'} #Output = "TEMPORARY_OUTPUT"

They were done on a different processing algorithm, but "memory:" always gives output_... and the temporary gives me the name of the action like Clipped_...

I have found no way of getting the complete path to the temp folder where the files should be.

Thank you!

  • There is already an issue in your reasoning. You tell us you run native:buffer. It returns a vector layer. The input from r.patch are one or more raster. There is a missing part between the two IMHO. The r.patch GRASS doc confirms it grass.osgeo.org/grass78/manuals/r.patch.html#parameters You need between both to "Rasterize" your vector buffer. – ThomasG77 Jun 9 at 22:18
  • You are correct I just gave to pieces of code to explain the problem, I can update it and give a bigger portion of code instead – EnGIsNowhere Jun 9 at 22:43
  • No, it's fine. At least I understand. You may look at github.com/qgis/QGIS/pull/36618. Could be related to your issue depending of you QGIS version. Fix in the issue = 19 days ago. Last 3.10 release = 25 days ago. Need to build QGIS to confirm or wait for the next QGIS 3.10 release minor version package. – ThomasG77 Jun 9 at 23:01
  • Nevermind you actually helped me find my mistake. My rasterize was with processing.run() instead of processing.runAndLoadResults() so I thought it was a path error but the layer simply wasn't there to begin with... – EnGIsNowhere Jun 9 at 23:04
0

ThomasG77 helped me realize I forgot to use processing.runAndLoadResults and instead I used only processing.run for my rasterize which meant my raster layer had never been added to my project and I was trying to access something that wasn't there.

for reference here was my rasterize code before:

processing.run("grass7:v.to.rast", \
{'input':tmp_riv_ponc_Intersect_Buffered,\
'type':[0,1,3],\
'where':'',\
'use':2,\
'attribute_column':None,\
'rgb_column':None,\
'label_column':None,\
'value':1,\
'memory':300,\
'output':'TEMPORARY_OUTPUT',\
'GRASS_REGION_PARAMETER':None,\
'GRASS_REGION_CELLSIZE_PARAMETER':cellsize,\
'GRASS_RASTER_FORMAT_OPT':'',\
'GRASS_RASTER_FORMAT_META':'',\
'GRASS_SNAP_TOLERANCE_PARAMETER':-1,\
'GRASS_MIN_AREA_PARAMETER':0.0001})

QgsProject.instance().mapLayersByName('Rasterized')[0].setName('Riv_Ponc_Intersect_Rasterized')
tmp_riv_ponc_Intersect_Rasterized = QgsProject.instance().mapLayersByName('Riv_Ponc_Intersect_Rasterized')[0].source()

And now the updated version:

processing.runAndLoadResults("grass7:v.to.rast", \
{'input':tmp_riv_ponc_Intersect_Buffered,\
'type':[0,1,3],\
'where':'',\
'use':2,\
'attribute_column':None,\
'rgb_column':None,\
'label_column':None,\
'value':1,\
'memory':300,\
'output':'TEMPORARY_OUTPUT',\
'GRASS_REGION_PARAMETER':None,\
'GRASS_REGION_CELLSIZE_PARAMETER':cellsize,\
'GRASS_RASTER_FORMAT_OPT':'',\
'GRASS_RASTER_FORMAT_META':'',\
'GRASS_SNAP_TOLERANCE_PARAMETER':-1,\
'GRASS_MIN_AREA_PARAMETER':0.0001})

QgsProject.instance().mapLayersByName('Rasterized')[0].setName('Riv_Ponc_Intersect_Rasterized')
tmp_riv_ponc_Intersect_Rasterized = QgsProject.instance().mapLayersByName('Riv_Ponc_Intersect_Rasterized')[0].source()
| improve this answer | |
  • Accept your own answer so people know they don't need anymore to answer to your question. – ThomasG77 Jun 9 at 23:11
  • I can't when I try it says I gotta wait 2 days to accept my own answer – EnGIsNowhere Jun 10 at 12:02

Your Answer

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

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