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

2
  • 1
    Is the data type for DIST_EDGE string or numeric? String values are accessed with quotes, numbers are not.
    – phloem
    Jan 7, 2015 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, 2015 at 18:37

1 Answer 1

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'
1
  • 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, 2015 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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