I've got a shapefile with about 30 fields that I'll need to update from time to time by importing a CSV with new data, joining it to the shapefile, and using the field calculator to carry the new values into the old fields one at a time:

enter image description here

However, this is a tedious process, and it seems like something ripe for automation with pyQGIS. The target field names and corresponding join field names will not change over time.

I have a sense of what this would look like in SQL, but the python version escapes me, and this documentation is thin on field calculation.

Is it even possible to automate a batch of field calculations like this?

  • So it's just the update that you want to script? – Nathan W Apr 25 '14 at 5:47
  • Exactly; string together multiple updates. And the schema will be the same every time, just the values will change. – Bill Morris Apr 25 '14 at 14:22

Since the ultimate destination of this file was PostGIS, I moved the process to a SQL script. It'd be nice to know how to do this with pyqgis, but no longer necessary for my purpose.

  • You could try using a model in the Processing Toolbox – Antonio Locandro May 15 '14 at 19:35
  • Good call, but I was hoping to see code :) – Bill Morris May 20 '14 at 18:56

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.