Select to view content in your preferred language

Creating a new field from a field that contains multiple values represented as text

612
2
Jump to solution
10-11-2021 12:30 PM
nalniuq
New Contributor

I'm trying to take a field called Code List which contains the abbreviations for mineral deposits (ex: AU CU PB) either convert this to a field which contains multiple values (one for each mineral) or create new fields for each mineral but am not sure how to go about this.  Any advice would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Imagine this is your current data structure:

ID| StringField | CodeList
 1 | abc              | AU CU PB
 2 | def               | AU

 

 

To get this structure:

ID| StringField | CodeList
 1 | abc              | AU
 2 | abc              | CU
 3 | abc              | PB
 4 | def               | AU

Use the script I provided in this question.

 

To get this structure:

ID| StringField | AU | CU | PB
 1 | abc              |    1 |     1 |   1
 2 | def               |    1 |     0 |   0  

  • for each mineral:
    • create the field
    • calculate the field, switch to Arcade, use this expression:
var codelist = $feature.CodeList
if(IsEmpty(codelist)) { return 0 }
if(Includes(Split(codelist, " "), "AU")) { return 1 } // change mineral here!
return 0

 


Have a great day!
Johannes

View solution in original post

2 Replies
DavidPike
MVP Frequent Contributor

Not sure exactly what your data structure is, perhaps a small example would help respondents, but possibly Pivot Table (Data Management)—ArcGIS Pro | Documentation

 

JohannesLindner
MVP Frequent Contributor

Imagine this is your current data structure:

ID| StringField | CodeList
 1 | abc              | AU CU PB
 2 | def               | AU

 

 

To get this structure:

ID| StringField | CodeList
 1 | abc              | AU
 2 | abc              | CU
 3 | abc              | PB
 4 | def               | AU

Use the script I provided in this question.

 

To get this structure:

ID| StringField | AU | CU | PB
 1 | abc              |    1 |     1 |   1
 2 | def               |    1 |     0 |   0  

  • for each mineral:
    • create the field
    • calculate the field, switch to Arcade, use this expression:
var codelist = $feature.CodeList
if(IsEmpty(codelist)) { return 0 }
if(Includes(Split(codelist, " "), "AU")) { return 1 } // change mineral here!
return 0

 


Have a great day!
Johannes