1

I'm trying to reclass values in field calculator using Python.

I want any value >= '5' to remain the same (return same value). Anything else to be = '0'.

Yes, DIST_EDGE are numbers.

I'm getting an invalid syntax error in Line 1 (see below)

Here's what I came up with (new script following comments):

enter image description here

Error Message:

enter image description here

  • 1
    Is the data type for DIST_EDGE string or numeric? String values are accessed with quotes, numbers are not. – phloem Jan 7 '15 at 17:06
  • Once you call the function Reclass(!POINTS_Adelard.DIST_EDGE!), the passed value is stored in a variable, no '!'. I've updated my answer below. – phloem Jan 7 '15 at 18:37
4

Assuming the data type for DIST_EDGE is numeric, the function should be (note, no quotes):

def Reclass(dist):
    if dist >= 5:
        return dist
    else:
        return 0

However, if DIST_EDGE is a string data type, you must cast it to a number before making your comparison:

def Reclass(dist):
    if int(dist) >= 5:
        return dist
    else:
        return '0'
  • 3
    These functions will work. The actual problem with the OP's code is that his function is using !POINTS_Adelard.DIST_EDGE! as a parameter name, which is of course invalid Python syntax. Replacing those references in the function (but not the final function call) with dist (as in @phloem's examples) will resolve this. – nmpeterson Jan 7 '15 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.