TransWikia.com

Workflow automation QGIS - populating attribute table

Geographic Information Systems Asked by Curious Girl on January 15, 2021

Is there a tool in QGIS which populates fields within the attribute table?

I know I can edit it manually but what I want is to include that tool in the workflow automation process.

I want to label the output rather than putting in on the key of the map. In order to label I need to have a field where I can add the label. Since this is part of a larger process in the Graphical Modeler I need to automate it rather than adding the field and name manually. What I’m interested in is if there is a tool or Expression in the Field Calculator that can return the name of the input layer and add it to the attribute table of the new/ output layer of the Field Calculator tool

One Answer

There are several options I may refer you to

  1. "Field calculator": qgis:fieldcalculator

Opens the field calculator. You can use all the supported expressions and functions.

A new layer is created with the result of the expression.

The field calculator is very useful when used in The graphical modeler.

  1. "Refactor fields": qgis:refactorfields

Allows editing the structure of the attribute table of a vector layer.

Fields can be modified in their type and name, using a fields mapping.

The original layer is not modified. A new layer is generated, which contains a modified attribute table, according to the provided fields mapping.

Refactor layer fields allows to:

  • Change field names and types
  • Add and remove fields
  • Reorder fields
  • Calculate new fields based on expressions
  • Load field list from another layer
  1. Advanced Python field calculator: qgis:advancedpythonfieldcalculator

Adds a new attribute to a vector layer, with values resulting from applying an expression to each feature.

The expression is defined as a Python function.

  1. Execute SQL: qgis:executesql

Runs a simple or complex query with SQL syntax on the source layer.

Beside a simple query, you can add expressions or variables within the SQL query parameter itself. This is particulary useful if this algorithm is executed within a Processing model and you want to use a model input as a parameter of the query. An example of a query will then be SELECT * FROM [% @table %] where @table is the variable that identifies the model input.

The result of the query will be added as a new layer.


Answering the question "Expression in the Field Calculator that returns the name of the input layer?"

As was mentioned by @Alexandre Neto:

you can get the layer name using the variable /@layer_name, there is also the /@layer_id.

Check this article for more details: "Exploring variables in QGIS pt 3: layer level variables".

Answered by Taras on January 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP