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)

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.

  • Thank you very much for your prompt reply. well, somehow your offered Approach would work but maybe I should explain what exactly I am going to do. I have a table geodatabase and each of the fields in this table is the outcome of some statistics on one of my Feature classes. The Point is, this Feature class attributes are going to be updated regularly and I want that the gdb table get updated automatically as well. Do you think it works with your offered Approach? – mari Dec 11 '13 at 15:26
  • In your above Approach, there is a Problem. well the summerized table cannt be joined to the first attributes since it would be one-to-many relationship and I tried to relate them but after updateing the first table, the summerized table would not be updated. – mari Dec 11 '13 at 15:48
  • @mari To answer your first question, I don't think this is possible in ArcMap proper. The output of Summary Statistics is not a live, automatically updating equivalent of a SQL GROUP BY query that sums values; it's static. This may be possible if you connected to SQL server or ArcSDE which had the desired query in SQL, but that's beyond my expertise. Regarding your second question, you should be using join and not relate--join can support one-to-many relationships. – dmahr Dec 11 '13 at 15:52

You may want to look at relationship classes. They can enforce referential integrity, e.g. update one feature when another is updated. I'm not sure if it works on multiple fields in one table though.


  • I am trying to use python code as stand-alone or even inside field calculator but I face error. could somebody assist me with my code? – mari Dec 12 '13 at 10:57

Your Answer

