1

I have merged numerous datasets that have the same attributes in different fields. I have TotalAcres, Total_Acres_Burned, TTL_ACRS, etc... I am trying to use field calculator to populate one field (TotalAcres) with all the acres values from the varying fields.

Using ArcMap 10.4.1 and python as parser.

Here is my code

def updateAcres ( TTL_ACRES, TotalAcres, ContrAcres, FIRE_SIZE, Field9, 
Total_Acres_Burned):
  if TTL_Acres > 0:
    TotalAcres = TTL_Acres
  elif ContrAcres > 0:
    TotalAcres = ContrAcres
  elif FIRE_SIZE > 0:
    TotalAcres = FIRE_SIZE
  elif Field9 > 0:
    TotalAcres = Field9
  elif Total_Acres_Burned > 0:
    TotalAcres = Total_Acres_Burned
  else: 
    return TotalAcres

Then my CodeBlock is: TotalAcres= !TotalAcres!

It runs without throwing an error but it does not populate TotalAcres with the value from any of the other Acres fields.

Any ideas?

enter image description here enter image description here

enter image description here

3

You need to use the return method to write the new data to the field.

Pre-logic script code:

def updateAcres ( TTL_ACRES, TotalAcres, ContrAcres, FIRE_SIZE, Field9, 
    Total_Acres_Burned):
      if TTL_Acres > 0:
        return TTL_Acres
      elif ContrAcres > 0:
        return ContrAcres
      elif FIRE_SIZE > 0:
        return FIRE_SIZE
      elif Field9 > 0:
        return Field9
      elif Total_Acres_Burned > 0:
        return Total_Acres_Burned
      else: 
        return TotalAcres

function to call:

updateAcres(!TTL_ACRES!, !TotalAcres!, !ContrAcres!, !FIRE_SIZE!, !Field9!, 
!Total_Acres_Burned!)
  • Thanks for the suggestion. This code turned every row in TotalAcres to NULL. Where am I missing how to assign the values from the other acres fields to TotalAcres? – sparky May 8 '18 at 18:00
  • 2
    @sparky i think you are confusing Code Block with the calling of the function and need to switch them. – BERA May 8 '18 at 18:45
  • 1
    Yes. Look at this example, and the screenshot a bit higher: desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/… – BERA May 8 '18 at 19:09
  • 1
    @sparky You are doing something incorrect. For example Spelling, indentation, case (LARGE or small letters), field type is text etc. You need to check all this again. – BERA May 9 '18 at 5:09
  • 1
    It was an indentation error of one space. It would be nice if Field Calculator allowed for tabs. Thank you for your help. – sparky May 10 '18 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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