wrobeln

Calculate field based on substrings within a string contained in another field

Discussion created by wrobeln on May 2, 2014
Latest reply on May 2, 2014 by mdenil
Hi

I am in need of a python code block that I can place into the calculate field tool in model builder.

I have a field called REF_ID.

REF_ID contains a string which is essentially just a list of semi-colon separated codes eg 59333; 10203; 61297; 12345 etc.

From REF_ID I want another field called DATA_SOURCE to be calculated.

DATA_SOURCE needs to be populated with text descriptions of particular codes, not all of the codes, within the REF_ID field.

So, I think I need to set up a library of the specific codes and their corresponding descriptions.

59333 Gravity
59334 Magnetics
61297 Radar
61299 Landsat
62227 Fieldwork

The python code then needs to search the string in the REF_ID field and look for the occurrence of any of the codes listed above.
Not all will be present and of those that are present, they should only occur once.

The DATA_SOURCE field should then be populated with a semi-colon separated list of the corresponding descriptions.
eg. Gravity; Radar; etc.

Does anyone have a good solution for this?

Much obliged.

Neil Wrobel

Outcomes