I have a shapefile with an attribute that I need to convert based on categorical rules. Hereby the TARGET / new values always stay the same and only the input values change. For example:

"Residential Area" assign if value "TYP" = 1 "Industrial Area" assign if value "TYP" = 2 "Mixed Area" assign if value "TYP" = 3 OR 4

I would like to create a dialog where the user is prompted to assign each original value to a set of predefined possible options.

I know I could do this in the field calculator but I would like it to be in the form of a menu mask where you set:

  1. Input Shapefile
  2. Value Assignment based on a table where all target variables are set and te input has to be select from a pulldown menu.

I have looked in the value map widget but have not found what I am looking for.

Any ideas?

  • The value map widget and the value relation widget are the way to have one set of user-friendly input values that correspond to a less user-friendly set of stored values in the attribute table. But it sounds like you want a custom form to pop up prompting the user to set up those widget settings. That would probably require some highly advanced coding on your part. Can you instead provide your user with additional documentation that teaches them how to set up a field edit widget? – csk Nov 18 '19 at 19:16
  • I thought that this might be the easiest thing to do, too... Would you go for the field edit widget or the field calculator... – S.Kasanmascheff Nov 19 '19 at 7:53
  • As I said, I found little documentation on the field edit widget. It seemed to me that the field conversions pertain mainly to the stage after digitizing a new object. In my case I want to create a new field and convert all existing object values to the new ones... – S.Kasanmascheff Nov 19 '19 at 7:54
  • I believe that the desired solution it´s a form of a model where it's possible to map all unique values ​​within a field, so the user will know which ones are present and which values ​​he will put in response to a CASE. ibb.co/j8RcM98 Something like what happens inside the attribute table when we click "All Unique". In modeler I could only show which fields exist in a shape, through the fields mapper, could not display the values ​​contained in this way. – Herbert Santos Nov 19 '19 at 18:22
  • I used this function now in the field calculator to have a list of the values that I need to convert and also to feed them in the expression builder by double-click thus avoiding typing errors. Thank you. – S.Kasanmascheff Nov 20 '19 at 14:16

Based on the additional information you provided in the comments, it sounds like you already have a field with values in it, and you want to create a new field with new values, where each new value replaces a specific old value.

If I correctly understood your question, the Field Calculator is a better way to do this than a field edit widget.

Take the original values and their corresponding new values from your lookup table, and put them in the following expression (add new when...then lines to include all the values):

case when "fieldname" = 'originalvalue1' then 'newvalue1' 
when "fieldname" = 'originalvalue2' then 'newvalue2'
when "fieldname" = 'originalvalue3' then 'newvalue3'
when "fieldname" = 'originalvalue4' then 'newvalue4'
else "fieldname"

Open the Field Calculator, and use that expression to create a new field.

| improve this answer | |
  • Thank you, that is exactly what I did.. – S.Kasanmascheff Nov 20 '19 at 14:14

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.