8

Not sure if I'm missing something very basic or not, but I have 6 or 7 shapefile vector layers in a dozen or so models that I need to update a single field with a rather simple formula. I could spend the time to simply edit each layer and update the field, but I was hoping to use the processing modeler to take advantage of batch processing. My trouble is that I'm not understanding how to use the modeler to update existing layers - I've used it several times to create a new layer, but not update any existing ones. I assume I'm just missing a piece of the puzzle?...

An example is that I have a field called "MNCPL_ID" which I want to update with: lpad( "STREETID" ,4,0) || lpad( "SEGMNTID" ,3,0) || lpad( @row_number,3,0) - easily done layer by layer with the field calculator, but how can I automate the process?
(Bonus points if you have a suggestion to make the last 3 numbers sequential for each "STREETID" instead of using @row_number)

*Not familiar with python scripts / still learning.

CEL-ma
  • 1,015
  • 7
  • 18
  • The processing toolbox has a field calculator tool, but it creates a new layer instead of updating the existing layer. – csk Apr 16 '18 at 18:04
  • Thanks - but yeah, that's exactly my dilemma - I'd like to use it to update the layer that's selected as the input rather than create a new one. – CEL-ma Apr 16 '18 at 20:16
  • @CEL-ma - You will need to use a script to update existing layers. The modeler typically creates temporary (or a final) output for most available tools. – Joseph Apr 17 '18 at 09:21
  • Thanks - that's what I was afraid of. I don't have any experience with scripts yet... not even really sure where to begin. – CEL-ma Apr 20 '18 at 12:38

1 Answers1

5

The Networks plugin for QGIS has a tool to create or update an existing field, which can be used in a model or run in batch processing.

enter image description here enter image description here

In the following example, the model updates the "azimuth" field with a formula. A temporary or final layer is not created, the existing one is simply updated.

enter image description here

egofer
  • 349
  • 4
  • 7
  • The problem is: Can you run that algorithm in a model to update a layer instead of create a new one? – Gabriel De Luca Dec 19 '19 at 19:25
  • Yes to everything: it can be used in a model and allows you to create new fields or update existing ones. – egofer Dec 20 '19 at 20:18
  • Tried this out and it works perfectly for what I wanted! thanks – CEL-ma Dec 23 '19 at 18:03
  • I don't understand why you cannot select the "field" manually in the model builder. Why do you have to write manually "azimuth"? – simone100 Feb 16 '23 at 08:21
  • @simone100 The plug-in allows you to select an existing field from the 'Field' drop-down list to update it, or to enter the name of a new field to be created (by additionally filling in the 'Size', 'Type' and 'Precision' options). – egofer Feb 17 '23 at 09:30
  • yes, now I see. – simone100 Feb 17 '23 at 12:09