I'm building a municipal model with many pipes, manholes & other structures as vector layers - these are coming from several different sources of information and the field structure can be slightly different depending on the source. I then need to add many new fields to each table for field data capture. What I'm wondering, is if there's a way to build an empty table within a template, or a script that I can run (or something else) to automate this task? I'll have many tables that I need to add these same fields to in this project, and I've got another dozen similar projects after this one... I would really like to find a way to add these same fields automatically rather than manually.

  • You want to create shapefiles using a script essentially? Where are the fields currently stored? – HeikkiVesanto Nov 24 '17 at 22:16
  • That's what I'm trying to solve - I've got 15-20 fields that I need to append to multiple layers in multiple projects. I could easily edit each layer by simply adding the new fields manually, but that would certainly be very time-consuming. If there's a way to have layers with the new fields loaded so I could somehow merge, or if there's a script I could use to automate adding new fields to a layer... – CEL-ma Nov 27 '17 at 13:53

I'm sure this can be done with a script as well. But the easiest way to do it would be using the Processing Modeler. From Processing> Graphical Modeler...

There is the "Add field to attributes table" function.

Simply create model that adds the fields that you need and run it for each table. You can even run it in batch mode for multiple layers at once.

enter image description here

  • Thanks! that's a great suggestion! however, if I understand correctly, the only issue is that the method you suggest only works for one field at a time? (I've got about 20 to append to each layer) I've tried using the same idea with the graphic modeler, but with the Merge Vector Layers algorithm - but this one's not working for me either - I'm getting an error saying the layers must have the same geometry type. My layer with the empty fields is "LineString" and the layer I'm trying to append to is "LineStingZ". If I save as with 'include Z' I get "LineSringZM" – CEL-ma Nov 27 '17 at 21:00
  • You can string multiple "Add field to attributes table" commands in a row. – HeikkiVesanto Nov 28 '17 at 10:47
  • 1
    Figured out how to string them together - thanks so much! – CEL-ma Nov 28 '17 at 14:29
  • No problem. Happy to help. – HeikkiVesanto Nov 28 '17 at 14:39

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.