1

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?

Bera
81.7k14 gold badges84 silver badges197 bronze badges
asked Jan 6, 2017 at 0:52
0

1 Answer 1

7

You have a repeated typo: match.fabs instead of math.fabs. math is a python library, fabs is the absolute value function.

answered Jan 6, 2017 at 1:14
2
  • Thanks J Kelly. I fixed that and the expression and everything worked. Commented 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? Commented Feb 26, 2017 at 1:30

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.