My question is in two parts :
1) How do I modify my pre-existing QGIS 2.18 script to work in QGIS 3? (i'm still learning Python)
2) How do I modify it to join only specific fields (i.e. i dont want to join all 20+ columns)
The script I used in QGIS 2.18 to create joins between a shp file and csv.
import processing
shpField='nd_id'
csvField='pt_nd_id'
result = processing.runandload('qgis:joinattributestable', shp, csv, shpField, csvField, None)
However this script doesn't work in QGIS 3 due to changes in processing.runandload
which is now processing.runAndLoadResults
and as far as I can tell there might be some changes to joinattributestable
(?)
i've already looked at QGIS 3 - Python : QgsVectorLayerJoinInfo issue and this Performing specific table joins in QGIS via python? and based on these i've cooked up the following : (NB: I'm trying to join between 2 shpfiles here)
QgsProject().instance().mapLayersByName('t_alpha')[0]
QgsProject().instance().mapLayersByName('t_beta')[0]
lien = QgsVectorLayerJoinInfo()
lien.setJoinFieldName('ID_alpha')
lien.setTargetFieldName('ID_beta')
lien.setJoinLayerId(layerToJoin.id())
lien.setUsingMemoryCache(True)
lien.setJoinLayer(layerToJoin)
target.addJoin(lien)
But this codes returns
...IndexError: list index out of range
Any advice/ clues?
layerToJoin
andtarget
variables.