Sunday 7 August 2016

qgis - Joining table to shapefile with pyQGIS


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?



Answer



You can find working code for attribute joins in the source of processing JoinAttributes.py: https://github.com/rldhont/Quantum-GIS/blob/master/python/plugins/processing/algs/qgis/JoinAttributes.py ... basically, you loop over both layers and compare manually.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...