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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 7, 2015 at 17:02
2
  • 1
    Is the data type for DIST_EDGE string or numeric? String values are accessed with quotes, numbers are not. Commented 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. Commented 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'
answered Jan 7, 2015 at 17:10
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. Commented Jan 7, 2015 at 18:57

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.