[GIS] How to fill attribute field of one feature based on calculation on attribute field of another feature

arcgis-desktoparcmapfield-calculatorrelates

I would like to fill an Attribute field of a geodateabase table based on some calculations such as 'sum' over specific field of another Feature class. Is there an Approach to formulate it? while in the "field calculator" we are able just to introduce a Formular inside that specfic Feature.

I am thinking about coding for this reason but to be honest as I am not pro in coding, I am sure what is the right way to think about it.

I would be thankful to have your assistant with my python code.

   import arcpy

   from arcpy import env

   # Set the current workspace 
   env.workspace = "K:\Lines\M966KAZ\55_SdiGis\45_Gdb\File\Test_Corridor_relationship.gdb"


  table = "link/to/Corridor_stat.dbf"
  fc = "link/to/Corridor_test_1.shp"

  # Create a search cursor
  rowsFc = arcpy.SearchCursor(fc) 

  # Create an update cursor
  rowsTable = arcpy.UpdateCursor(table)


  for rowT in rowsTable:
     if fc.Corridor_S <= 1:
       valueTable = sum (fc.SHAPE_Leng)
  elif (fc.Corridor_S > 1 and fc.Corridor_S <= 60):
       valueTable = sum (fc.SHAPE_Leng)
  elif (fc.Corridor_S > 60 and fc.Corridor_S <= 100):
      valueTable = sum (fc.SHAPE_Leng)

Best Answer

The code block in Field Calculator can be used to gather/aggregate statistics within multiple features of the specified feature class. However, it's not really practical when dealing with multiple feature classes.

The easiest method would probably be to generate a table of the 'sum' statistics you want using the Summary Statistics tool and then join this output to the first feature class using the Add Join tool or the regular join menu from the table of contents.

Related Question