1

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

ie, JOIN ON layer1field1 = layer2field1 AND layer1field2 = layer2field2

If so, how?

1

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.

1

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

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.