I have created a table join between two shapefiles which I've named 'OSMM' and 'Mastermap'. I want to copy and paste all features (polygons) without a match from the target layer ('Mastermap') into the parent shapefile ('OSMM'). I can't find any up-to-update code for QGIS 3.6.
Here is my code so far:
#1. loads the SHP files
uri = 'C:/Users/xx/Downloads/OSMM.shp'
vlayer = iface.addVectorLayer(uri,"","ogr")
uri = 'C:/Users/xx/Downloads/Mastermap.shp'
vlayer = iface.addVectorLayer(uri,"","ogr")
#2. Joins "InvoiceNum" from OSMM to Mastermap
layerToJoin = QgsProject().instance().mapLayersByName('OSMM')[0]
target = QgsProject().instance().mapLayersByName('Mastermap')[0]
myJoin = QgsVectorLayerJoinInfo()
myJoin.setJoinFieldName('InvoiceNum')
myJoin.setTargetFieldName('InvoiceNum')
myJoin.setJoinLayerId(layerToJoin.id())
myJoin.setUsingMemoryCache(True)
myJoin.setJoinLayer(layerToJoin)
myJoin.setJoinFieldNamesSubset(['InvoiceNum'])
target.addJoin(myJoin)
#3. Selects NULL features from Mastermap
params = { 'EXPRESSION' : '"OSMM_InvoiceNum" is NULL', 'INPUT' : 'C:/Users/xx/Downloads/Mastermap.shp', 'METHOD' : 0 }
processing.run("qgis:selectbyexpression", params)
So how do I perform the PyQGIS version of Ctrl+C on 'Mastermap' and Ctrl+V into 'OSMM'?
Presumably I will then need to use the following code:
#5. Save the changes
OSMM.commitChanges()
