3

I am trying to calculate a reinspection date for surveys using the field calculator in ArcGIS Pro. I am using a predefined survey date and risk zone for this calculation. The risk zones are LOW, MED and HIGH. Low risk zones are reinspected every 1825 days, medium every 1095 days and high every 486 days. I am trying to use the known survey date and known risk zone to calculate the new reinspection date in the field calculator. This is what I have done in the field calculator :

Expression line: reclass(!SurveyDate!,!RiskZone!)
 
def reclass(SurveyDate, RiskZone):
 if (RiskZone == 'HIGH'):
 return SurveyDate + datetime.timedelta(days=486)
 elif (RiskZone == 'MED'):
 return SurveyDate + datetime.timedelta(days=1095)
 elif (RiskZone == 'LOW'):
 return SurveyDate + datetime.timedelta(days=1825)

I validate the script and it confirms it is correct, however, when I run it an error message pops up.

ERROR 000539: Traceback (most recent call last):
 File "<expression>", line 1, in <module>
NameError: name 'MED' is not defined

Why is this happening? I'm not sure where the fault may be.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 16, 2021 at 13:47
1
  • Everything looks good. Something sinister here... Are these strings coming from associated domain by any chance Commented Jun 17, 2021 at 5:12

1 Answer 1

3

As you can see from the error, it is complaining about line 1. There is no MED in Line 1 of the code block, but there IS a MED in line 1 of some iterations of the expression line.

And it's not quoted, and therefore treated as a variable name (and it is not a variable, hence the name error).

Change the expression to treat string inputs as a string literal:

reclass(!SurveyDate!,'!RiskZone!')

Remember that ArcGIS field calculator is doing a literal interpolation of values here.

(Fixed it for me when testing with your exact code in ArcGIS Pro.)

answered Jun 17, 2021 at 3:19
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.