I have a polygon feature with three attribute columns. The values in each of the attribute columns are number coded. I want to generate an ID (fourth column) for the unique combination of the values of the attribute columns. Rows with similar attributes are assigned same ID

Attrib1 Attrib2 Attrib3 ID

1 1 33125
2 2 34020
1 2 60014
1 1 40290
3 1 55041
1 3 55047
2 3 56008
1 1 56026
3 3 56032
1 1 56035
1 1 57103

There are several thousands rows that it is time consuming to identify the unique combinations and assign ID manually.

Thanks in advance.

  • Can you please clarify your question? Do you mean want to concatenate the three attributes? So the first record would be 1133125? Then, ID would be 1. If another combination of attributes is also 1133125, then the ID would also be 1? Or do you want the ID to just be the concatenation of the three fields? – Fezter Nov 12 '13 at 2:10
  • I think the ID field being a concatenation of the 3 Attrib fields would be a very logical way to go because it would be human readable, rather than being entirely abstract (assuming you know the 'Attrib' data well enough of course). – MappaGnosis Nov 12 '13 at 8:37

Slow but simple decision:

  1. Read your data in the list of tuples (attrib1, attrib2, attrib3)
  2. Create a set object from this list (or even better - a dictionary based on this set with unique tuples as keys and unique ID's as values)
  3. Iterate over the attribute raws and define the index of every touple from the set or dictionary.
| improve this answer | |

Thanks to the suggestions. Here's what I did based on the suggestions above. 1.) Pad the coded values to get uniform length 2.) Concatenate the attribute values 3.) Use dictionary to assign ID to the concatenated codes.

These serves my purpose already.

Thanks guys.


| improve this answer | |
  • Could you post the code that worked for you in case someone else has a similar issue? – Paul Nov 14 '13 at 0:31

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.