I have written a small python plugin to refresh a join on a point layer in QGIS.
point_layer=None
for lyr1 in QgsMapLayerRegistry.instance().mapLayers().values():
if lyr1.name() == "point_layer":
point_layer = lyr1
text_table=None
for lyr2 in QgsMapLayerRegistry.instance().mapLayers().values():
if lyr2.name() == "text_table":
text_table = lyr2
POINT_ID='ID'
TEXT_ID='ID'
joinObject = QgsVectorJoinInfo()
joinObject.joinLayerId = text_table.id()
QgsVectorLayer.removeJoin(point_layer, text_table.id())
joinObject.joinFieldName = TEXT_ID
joinObject.targetFieldName = POINT_ID
joinObject.memoryCache = True
point_layer.addJoin(joinObject)
I tried to get a subset of fields to be used from joined layer text_layer.
joinObject.joinFieldNamesSubset = 'TYPE'
There is no error, but it joins all the fields, not only the field 'TYPE' (attribute of layer text_layer).
How can I set the attributes I want to join? And where do I have to call joinFieldNamesSubset
?