I am trying to run a field calculator python script that will take a value from one field in the attributes table and create an abbreviation in another field that was designated for it.
Here is a example of the code that was written for this function:
def checkValue(c,d):
if c == 'ARTERIAL_CRACKSEAL':
return 'ACS'
The problem is that once I created coded value domains for these attributes the code stopped working (i.e. code:1 description: ARTERIAL_CRACKSEAL ; code:2 description ARTERIAL_microseal ; etc.). Would anyone know how to adjust the code so the script runs successfully? I need to keep coded value domains for this attribute field.
-
1Please edit your question to include your code as text rather than just as an image. Code as text makes it easier for potential answerers to copy/paste your code snippet to test, instead of having to type it all out manually.Midavalo– Midavalo ♦2016年09月08日 18:06:58 +00:00Commented Sep 8, 2016 at 18:06
1 Answer 1
In a coded value domain, the values are stored as 1
, 2
, 3
and not as ARTERIAL_CRACKSEAL
, ARTERIAL_MICROSEAL
, ARTERIAL_OVERLAY
.
To make your code work with the coded values, change your if
lines to refer to the codes:
def checkValue(c, d):
if c == 1:
return 'ACS'
if c == 2:
return 'AMS'
if c == 3:
return 'AOL'
if c == 4:
return 'TRM'
if c == 5:
return 'FST'
-
I have tried that as well and it did not seem to work unfortunately.Davor Romic– Davor Romic2016年09月08日 18:17:27 +00:00Commented Sep 8, 2016 at 18:17
-
What errors did it return? can you include a screenshot of your domain settings and some of your data?2016年09月08日 18:19:56 +00:00Commented Sep 8, 2016 at 18:19
-
1You may have already checked this, but make sure the types of your coded values and values in your script match. In this example, make sure your coded values are stored as integers and not characters.mmoore– mmoore2016年09月08日 18:22:05 +00:00Commented Sep 8, 2016 at 18:22
-
I have tried it again by using the coded values instead of the description and including quotation marks around them. It worked fine this time, so your first answer was correct. I'm not sure if it was just the quotation marks or I did something else when I tried yesterday. Thank you for your help.Davor Romic– Davor Romic2016年09月08日 20:50:15 +00:00Commented Sep 8, 2016 at 20:50
-
1@DavorRomic if this has worked for you, please consider marking it as the answer. See What should I do when someone answers my question?2016年09月09日 00:05:08 +00:00Commented Sep 9, 2016 at 0:05
Explore related questions
See similar questions with these tags.