Hi,
I have the following attribute table. I need to update the fields using the field calculator (SEC, TOWN, RANG) by using the "mtrs" and "label" columns(fields) in the attribute table.
SEC: (letter S + label) TOWN: (string from mtrs) RANGE (string from mtrs) S_R_T (join the SEC+TOWN+RANG)
S24 T1N R14W S24-T1N-R14W
S4 T1N R14W S24-T1N-R14W
S34 T2S R8W S34-T2S-R8W
.
.
Can somebody help me to achieve this using the "Field Calculator" and Python parser functions?
Thanks a lot in advance.
Solved! Go to Solution.
ahhh... slicing again
x = 'abcdefghi__13E' # ---- since you didn't include an example ----
"R{}{}".format(int(x[11:13]), x[13]) # x = !mtrs!
'R13E'
"{}-{}-{}".format(!A!, !B!, !C!)
just replace A, B and C with your field names but keep the ! ! marks around them.
Obviously , this has to go into a text field and you have to specify python as the o\parserf
table is hard to read, but I suspect that you are also having trouble with the other bits, like getting the SEC field which would be
sectn = '024'
"S{}".format(int(sectn)) # in field calculator !sectn! with python parser
or are those ok... it isn't clear whether you need the whole process completed, just some bits, or all the work? And how much python do you know?
Thanks Dan. Yes I figured and it worked. I am a beginner to Python.
Did you find an alternate solution or do you want to close the thread?
Apologies for the late reply. Your answers were very helpful. Is there a way I can extract RANGE using the "mtrs" column?
Yes... what have you tried and what should it look like?
This type of functionality is simply python string slicing
other functions string functions
I used
"R{}".format(int(!mtrs![11:13])) but I am not able to get the East "E" or "W" letter attached like R1E or R18W.
ahhh... slicing again
x = 'abcdefghi__13E' # ---- since you didn't include an example ----
"R{}{}".format(int(x[11:13]), x[13]) # x = !mtrs!
'R13E'
You are genius. I got the trick now. Thanks a bunch.