The problem must be the definition of the output string, because I tried the same code but writing a route directly on the parameters list and it worked.

This is the code I wrote:

import processing

import os

#defines the folder

folder="C:/Users\Pueyo/Google Drive/Consultoria/Mapa escolar/Dades UMAT/heatmap"

#captures the files in the folder

filelist=os.listdir(folder)

feedback = QgsProcessingFeedback()

#if the file is a shapefile, run the algorithm

for file in filelist:

if file.endswith('.shp'):

layer=QgsVectorLayer(folder+file,file,'ogr')

file2 = file.replace(".shp","")

output=str(folder + "/hm200_" + file2 + ".tif")

parameters={'INPUT':layer,'RADIUS':200, 'PIXEL_SIZE':5, 'OUTPUT':output}

processing.runAndLoadResults('qgis:heatmapkerneldensityestimation',parameters,feedback=feedback)

I attach a screen capture of the code.

This is the error message I get:

Traceback (most recent call last):

File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 90, in runcode

exec(code, self.locals)

File "", line 1, in

File "", line 15, in

File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 138, in runAndLoadResults

return Processing.runAlgorithm(alg, parameters=parameters, onFinish=handleAlgorithmResults, feedback=feedback, context=context)

File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 183, in runAlgorithm

raise QgsProcessingException(msg)

_core.QgsProcessingException: There were errors executing the algorithm.

More Josep Pueyo-Ros's questions See All
Similar questions and discussions