I am trying to execute the processing algorithm extractbylocation
. Anyway, firstly I run that algorithm in QGIS3 and then just copy the code from the processing history and changes paths to variables. I have some features with invalid geometries (in QGIS in the settings it is set for processing to ignore that features),so that is maybe my problem. In order to avoid that I deleted all the features with invalid geometries and the problem is still there.
So my code looks like this:
input_path = 'C:/Users/file.shp'
output_path = 'C:/Users/file_out.shp
crs = QgsCoordinateReferenceSystem("epsg:4326")
input = QgsVectorLayer(input_path, "links", "ogr")
input.setCrs(crs)
#deleting features with invalid geometries
for f in input.getFeatures():
geom = f.geometry()
if geom.isGeosValid():
print('valid')
else:
input.deleteFeature(f.id())
print('not valid')
sys.path.append('C:/Program Files/QGIS 3.4/apps/qgis/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
processing.run("native:extractbylocation",
{'INPUT': input, 'PREDICATE': [1],
'INTERSECT': 'C:/Users/points.shp', #I also tried to put here the QgsVectorLayer object instead of path
'OUTPUT': outputh_path})
I got the error next to the output line in the processing algorithm.
File "path_to_my_file_py", line 49, 'OUTPUT': outputh_path})
File "path_to_my_file_py", line 84, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "path_to_processing_file_py", line 194, in runAlgorithm
raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.
And btw this code works at python console in qgis.