I wish to join one field from a shapefile to another shapefile within the QGIS graphical modeler. I am aware that there is a 'Join attributes table' algorithm but this joins all of the fields from the shapefile.

Outside of the graphical modeler, I can use the Joins process in the layer properties but I would much rather be able to use this function within my models.


1 Answer 1


You can achieve this by creating a custom script in the Processing Toolbox which you can then add to your modeler. To create one:

Processing Toolbox > Scripts > Tools > Create new script

Then add the following code:

##Target_field=Field Target_layer
##Join_field=Field Join_layer

from qgis.core import QgsVectorJoinInfo

layer_1 = processing.getObject(Target_layer) 
layer_2 = processing.getObject(Join_layer) 

joinObject = QgsVectorJoinInfo()
joinObject.joinLayerId = layer_2.id()
joinObject.joinFieldName = Join_field
joinObject.targetFieldName = Target_field

Make sure it is saved in C:\Users\You\.qgis2\processing\scripts for it to be available in the Processing Toolbox (you may need to close the script for the toolbox to update itself).

When you run the script, it should look like this:

Join script

where the user can choose the layers and fields to join. This has been tested in the QGIS modeler using QGIS 2.12.3-Lyon.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.