[GIS] Basic Python Reclass question in Field Calculator

arcgis-desktopfield-calculatorpython

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

Best Answer

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'
Related Question