Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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. qgis.org/pyqgis-cookbook/intro.html 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? qgis.org/api/structQgsVectorJoinInfo.html –  Matthias Kuhn Apr 23 '13 at 11:20
add comment

1 Answer 1

up vote 2 down vote accepted

You can find working code for attribute joins in the source of processing JoinAttributes.py: https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/JoinAttributes.py ... 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 gis.stackexchange.com/questions/90159 as a duplicate of this question. –  Devdatta Tengshe Mar 20 at 7:02
    
Never mind, I got the link, and updated it myself. –  Devdatta Tengshe Mar 20 at 7:05
add comment

Your Answer

 
discard

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.