5

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.

4
  • 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 9: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
4

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

3
  • 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

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.