I have a python script that I want to work in QGIS 3.0.
#importing all necessary modules
import processing, os, glob
result_path =("/home/brent/Documents/Hansen_new_data/Regions_Min/Province/TI/CADT/") #specifying the result path/directory
os.chdir("/home/brent/Documents/Hansen_new_data/Mindanao_provinces/") #changing the directory where the input files are located
clipper_path ="/home/brent/Documents/Hansen_new_data/Mindanao_provinces/"
for fname in glob.glob("*.shp"):
name = list(os.path.splitext(fname)) #convert an iterable to list
name[0] = name[0] + ""
newName = "".join(name)
print ("processing " + newName)
overlay = newName.replace(".shp", "_clipped.shp") #indicating the ouput shapefile by replacing some of its letter strings
input_vector = ("/home/brent/Documents/Hansen_new_data/Regions_Min/TI/CADT.shp") #specify the input vector to be clipped
#processing.runalg("qgis:clip", input_vector, fname, result_path + overlay) #run the clip algorithm
alg ="qgis:clip"
params = {"INPUT": input_vector,"OVERLAY": clipper_path+fname,"OUTPUT":result_path + overlay}
processing.run(alg, params)
print("Finish")
Please take note that the commented line (#processing.runalg("qgis:clip...) worked in 2.18. I tried to follow the new convention of QGIS 3 processing in this link.
This is the resulting error from the console:
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 22, in <module>
File "/usr/share/qgis/python/plugins/processing/tools/general.py", line 105, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "/usr/share/qgis/python/plugins/processing/core/Processing.py", line 183, in runAlgorithm
raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.
Is there something I missed with my python script?