Is it possible to join two layers in PyQGIS, on multiple fields?

ie, JOIN ON layer1field1 = layer2field1 AND layer1field2 = layer2field2

If so, how?


I do not think this is possible as this cannot be achieved via the GUI.

An alternative could be to duplicate layer1 which would allow you to join each layer1 with the relevant field of layer2.

| improve this answer | |

Your question uses the "AND" statement which suggest both field joins must be true for a feature to join. With that another alternative approach would be:

  • Create a new field called field3 in both layers
  • Field calculate field3 with the concatenation of field1 and field2 for both layers
  • Perform join on field3
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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