I have two shapefiles ('drenagem'
and 'rio_pri'
).
I need to loop through every feature from 'rio_pri'
and save all those features from 'drenagem'
that intersect 'rio_pri'
.
So I wrote the following code to run in Python Terminal.
import processing
drenagem = QgsVectorLayer('/home/tiago/Documentos/Rios_mata_disol.shp','Rios_mata_disol','ogr')
rio_pri = QgsVectorLayer('/home/tiago/Documentos/rios_linha_costa.shp','rios_linha_costa','ogr')
# Loop
for r in rio_pri.getFeatures():
processing.runalg("qgis:selectbylocation", drenagem, r,['intersects'],0,0)
r_cod = r['COCURSODAG']
path = r_cod+'.shp'
processing.runalg('qgis:saveselectedfeatures', drenagem, path)
Then for every feature from 'rio_pri'
I get this message at the console.
Unable to execute algorithm
Wrong parameter value: <qgis._core.QgsFeature object at 0x7ffb6620b770>
I guess I should not use the 'r'
as an argument of qgis:selectbylocation
, but I could not figure out what should I use instead. Any ideas?
I'm using QGIS 2.18.17 on Linux Mint 19.