AnsweredAssumed Answered

python compare two fields, update a third

Question asked by nickoday2005 on Jul 22, 2019
Latest reply on Jul 22, 2019 by bixb0012

I'm trying to compare two fields to each other and then use that information to update a third field.  Here are the fields that I have in my data:

      Field A:  Direction (numeric)

      Field B:  Bearing (numeric)

      Field C:  KeepDiscardFlag (text)

 

Below is the code that I've tried based on other discussions in GeoNet, but it doesn't work (errors out saying that it couldn't evaluate the python expression).  What I'm trying to do is this:

  1. Make sure that Direction and Bearing are not null
  2. Set the KeepDiscardFlag field to "Keep" if Bearing is between Direction (plus or minus 22.5), or
  3. Set the KeepDiscardFlag field to "Delete" if Bearing is not between Direction (plus or minus 22.5)

 

Expression

Reclass(!KeepDiscardFlag!, !Direction!, !Bearing!)

 

Code Block

def Reclass(KeepDiscardFlag, Direction, Bearing):
    if ( (Direction is None or Bearing is None) and (Direction - 22.5) <= Bearing <= (Direction + 22.5) ):
      KeepDiscardFlag = "Keep"
   elif ( (Direction is None or Bearing is None) or (Direction - 22.5) >= Bearing >= (Direction + 22.5) ):
      KeepDiscardFlag = "Delete"

 

 

Any help would be greatly appreciated!

Outcomes