Improving data attribution

Improving data attribution

by Bwalya Kapansa -
Number of replies: 1
In B003 Exercise, it was mentioned that the "id" can be filled with default values as maximum("id") + 1. Is it possible to do something similar for the EZ_ID field where, for example EZ001 the "EZ" comes from a different layer and the "001" comes from the id field? Like field calculator.
In reply to Bwalya Kapansa

Re: Improving data attribution

by Oualid Fouad -

Yes, it is possible to create a new field in QGIS using the Field Calculator that combines values from different fields. In your case, if you want to create a new field called EZ_ID where the first part comes from a different layer and the second part comes from the id field, you can use an expression like this:

concat("EZ_field", lpad("id", 3, '0'))

Here's a breakdown of the expression:

  • concat("EZ_field", ...): This function concatenates the values from the fields within the parentheses.
  • "EZ_field": This represents the value from the EZ_field in the other layer.
  • lpad("id", 3, '0'): This function left-pads the value from the id field with zeros to ensure that it is three characters long. Adjust the number 3 as needed based on the maximum expected value.

This expression assumes that the field in the other layer is named EZ_field. Please replace it with the actual name of the field from the different layer.

When you use the Field Calculator, create a new field, choose the output field type and length, and then enter the expression in the expression box. This will create a new field in your current layer (EZ_ID) with values like "EZ001", "EZ002", and so on. Adjust the field names and expressions according to your specific layer and field names.