I am trying to write a python script that iterates over the features of a layer, selects a features and feeds into processing.runalg(). I am pretty sure the selection is going on. However, the processing.runalg("qgis:xxx") bit ocurrs oblivious to the selection! I know there are plenty of similar questions and answers, but I have tried their suggestions and haven't been successful. I though maybe if someone sees the code maybe could help me resolve this.
Here is the code (indents in the for loops might be messed up from formatting):
inter_shpmemory = iface.addVectorLayer(main_directory + "\\" + intersect_shpname,"Zone layer",labtype) specieslayer_mem = iface.addVectorLayer(main_directory + "\\" + bd_shpname,"GBIF layer",labtype) ###Create a folder to safe all stuff newfolder = main_directory + "\\" + "Zonal_GBIF" if not os.path.exists(newfolder): os.makedirs(newfolder) it = specieslayer_mem.getFeatures( QgsFeatureRequest() ) inputLayerIds = [i.id() for i in it] #selects all of the input feature and one feature from the clip layer specieslayer_mem.setSelectedFeatures( inputLayerIds )###is this even #needed? features = inter_shpmemory.getFeatures() for feature in features: indbd_name = feature['simp_name'] inter_shpmemory.setSelectedFeatures([feature.id()]) print "Feature ID %d: " % feature.id() print indbd_name processing.runalg('qgis:clip', specieslayer_mem, inter_shpmemory, newfolder + '\\' + indbd_name +'.shp') inter_shpmemory.setSelectedFeatures() specieslayer_mem.setSelectedFeatures()
I can't get to do it what I want.