I'm working in Modelbuilder. I have a polygon in which I calculate the shape centroid in decimal coordinates (field called LONG_CENTR). Then I add a field (called FAJA) and I want to use a Field Calculator to assign it a value according to the centroid I've obtained previously. I think I have messed up the code in the field calculator.
Python-parser expression:
updateValue( !FAJA! )
Code Block:
def updateValue(FAJA) :
if (70.500 <= match.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) <= 73.500):
return 1
elif (67.500 <= math.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) < 70.500):
return 2
elif (64.500 <= math.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) < 67.500): return 3
elif (61.500 <= math.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) < 64.500):
return 4
elif (58.500 <= math.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) < 61.500):
return 5
elif (55.500 <= math.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) < 58.500):
return 6
elif (53.500 <= math.fabs(LONG_CENTR) and match.fabs(LONG_CENTR) < 55.500):
return 7
else:
return 0
The error I'm getting is:
ERROR 000539: Error running expression: replace( -69.256 )
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 2, in replace
NameError: global name 'match' is not defined
Failed to execute (Assign Faja Value).
What is causing this error?
1 Answer 1
You have a repeated typo: match.fabs instead of math.fabs. math is a python library, fabs is the absolute value function.
-
Thanks J Kelly. I fixed that and the expression and everything worked.user89183– user891832017年01月07日 00:56:28 +00:00Commented Jan 7, 2017 at 0:56
-
@inesingeniera If this answer worked for you, please consider voting and accepting. See What should I do when someone answers my question?2017年02月26日 01:30:03 +00:00Commented Feb 26, 2017 at 1:30
Explore related questions
See similar questions with these tags.