2

I'm trying to create a column with integer values based on a small function that basically uses conditional statements. In short, a reclassification. My attempt below:

def getValue(Etat): if Etat == 'Bon': value = 1 elif Etat == 'Moyen': value = 2 elif Etat == 'Mauvais': value = 3 elif Etat == 'Ruine': value = 4 value = getValue(<Etat>) 

While I do not get any errors, the problem is that the new field is not being updated with new values. My thoughts are that it can't find the original field: "Etat", the source.

How should I go about it? Also, what I don't understand how is going to make the updates to the field, surely something is missing.

1 Answer 1

2

Alright, due to my lack of not paying enough attention I managed to solved the problem.

I wasn't returning the value, only making assignments.

3
  • Could you help me? I'm trying to use the same toolbox to write the layer name in a new attribute column. I insert in the Formula field the same expression used in field calculator: "value = @layer_name". Unfortunately, python does not recognize the variable @layer_name. Commented Mar 25, 2019 at 20:04
  • @christian.gobel Hi. I could try but I'm entirely sure I understood everything. If I'm not mistaken @ character shouldn't be used as part of variable name unless that is some sort of new feature for qgis/arcgis which I am not familiar with. Could you share a little bit more of what you are trying to do? Commented Mar 28, 2019 at 18:21
  • sure. I posted my question [here] (gis.stackexchange.com/questions/316642/…). I Understand the @ are variables function from QGIS environment. That's why not work in python expression. Commented Mar 29, 2019 at 19:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.