Select to view content in your preferred language

Reclass python script not working

5072
12
Jump to solution
08-14-2012 10:47 AM
JenniferDick
Deactivated User
Hi,

I'm trying to reclass a vector field that has values from 1 to 7. I would like to reclass these values to 1's & 2's. For example:

if the value is 1 reclass it to 2
if the value is 2 reclass it to 2
if the value is 3 reclass it to 1

and so on.

Here is my script, but it is not working...any thoughts?

def Reclass( !Value! 😞
  if ( !Value! = 1):
    return 2
  if ( !Value! = 2):
    return 2
  if ( !Value! = 3):
    return1
  if ( !Value! = 4):
    return 1
  if ( !Value! = 5):
    return 1
  if ( !Value! = 6):
    return 1
  if ( !Value! = 7):
    return 1


reclass( !Value! )
Tags (2)
0 Kudos
12 Replies
BruceBacia
Frequent Contributor
This worked going integer to integer.  It may be the float vs. integer problem that's hanging it up ?
0 Kudos
JenniferDick
Deactivated User
Thanks for all the comments. I have the calculation working now. It was the Float and Integer fields causing the problem.
0 Kudos
DanielAmrine
Frequent Contributor
What about going from text to float?

I am trying to do reclass based on a text value to calcualte a buffer distance....

def Reclass(!DRILLTYPE!)
  if DRILLTYPE = U
    return 1177.5
  elif DRILLTYPE = V
    return 744.9
  elif DRILLTYPE = D
    return 744.9
  elif DRILLTYPE = H
    return 1053.4

This is what i put into the codeblock but it keeps giving me the parse syntax error mentioned above. Do I need to reclass the tex into numbers first?

Thanks!
Dan
0 Kudos