Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Joining shapefiles is a relatively straightforward proess in QGIS using 'add vector join' in the layer properties menu. I can add a csv file as a vector layer, as well as a shapefile, and join the two using a common field.

I would like to do a similar join using pyQGIS, however I can't seem to find any documentation on how to go about this. Is this possible to do programmatically using pyQGIS with 'add vector join' or the older 'Join by Attributes'? Or, alternately, might there be any other Python modules that might be able to merge a csv with a shapefile before loading as a map layer with pyQGIS?

share|improve this question
this is a general tutorial i came across when i started. i hope this works for u... – Ade'l Apr 18 '13 at 8:11
Have you checked the API documentation for QgsVectorLayer::addJoin and the provided data structure QgsVectorJoinInfo? – Matthias Kuhn Apr 23 '13 at 11:20
up vote 3 down vote accepted

You can find working code for attribute joins in the source of processing ... basically, you loop over both layers and compare manually.

share|improve this answer
Hi underdark, could you update this answer with the updated link? the current link is dead. We can then mark as a duplicate of this question. – Devdatta Tengshe Mar 20 '14 at 7:02
Never mind, I got the link, and updated it myself. – Devdatta Tengshe Mar 20 '14 at 7:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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