Using qgis:lineintersection in QGIS console?

Using qgis:lineintersection in QGIS console?

console usage for qgis:lineintersection processing tool has been given as below

processing.runalg('qgis:lineintersections', input_a, input_b, field_a, field_b, output)

and i loaded a polyline layer onto qgis and executed following commands in console

layer = qgis.utils.iface.activeLayer() provider = layer.dataProvider() columns = provider.fields() id=columns[0] processing.runalg('qgis:lineintersections', layer, layer, id, id,'output' )

lineintersection tool is working properly when i use it directly in qgis, but i want to execute it in console for which i m getting error as below…

Traceback (most recent call last): File "", line 1, in File "C:/PROGRA~1/QGISWI~1/apps/qgis-ltr/./python/pluginsprocessing", line 71, in runalg alg = Processing.runAlgorithm(algOrName, None, *args) File "C:/PROGRA~1/QGISWI~1/apps/qgis-ltr/./python/", line 317, in runAlgorithm if not param.setValue(args[i]): File "C:/PROGRA~1/QGISWI~1/apps/qgis-ltr/./python/", line 676, in setValue elif len(value) > 0: TypeError: object of type 'QgsField' has no len()

i think problem is with passing values in function

Can anyone give the solution?

I tried it out this code:

import processing layer = qgis.utils.iface.activeLayer() path = '/home/zeito/pyqgis_data/my_output.shp' processing.runalg('qgis:lineintersections', layer, layer, None, None, path )

for this situation:

and it worked. You don't need the id's (see the error 'QgsField' has no len() where I think the problem is). On the other hand, I used one absolute path and the name of output file with its respective extension (*.shp).

Watch the video: Intersect geoprocessing tool in QGIS