I need to update a field based on another layers field. I could do this in arcmap manually by joining the two layers together and then using field calculator. Is there a way I can do it with a script? I.e just enter the field as an input and run it and it will calculate the field I need.

I was thinking along the lines of

inputFC = arcpy.GetParameterAsText(0)

searchcursor, updatecursor? 

all I want is the average of a field in one layer to be entered into one row/column in another.

I should also add I want this as a script so it automatically creates a new field in the polyline and puts the average of the other layers field in it.

  • "all I want is the average of a field in one layer to be entered into one row/column in another" -- this statement is confusing, can you elaborate? Which row in the "other" table should the "average of a field in one layer" be entered? The first? Does the row already exist? – blah238 Oct 28 '11 at 4:33
  • sorry. I have a field of values in a layer (94) of them. I want the average of these values (e.g sum/94) to be inputted into a field with a polyline. I could do this manually by joining the layers, then using field calculator to AVG/values – Kari Oct 28 '11 at 4:37
  • Okay, lets say layer A is the layer with the 94 rows you want the average of field X. Layer B is what? A polyline layer with just one feature? Or are there many features? What is the relationship between A and B (one to one, many to one, etc)? – blah238 Oct 28 '11 at 4:59
  • yes, its a polylinez with just one feature. Layer A is a multipoint feature of the polyline, that is, the polyline converted to many points. – Kari Oct 28 '11 at 5:10
  • And they are related by a common ID I assume? Do you want the script to be generic enough that it can work even if Layer B has more than one feature? Sorry for the 20 questions. – blah238 Oct 28 '11 at 5:20

If I understand the details of the question correctly (described in the comments), I think you should be able to do all of this in two steps using built-in geoprocessing tools, which you can of course also script in Python:

  1. Use Summary Statistics (Analysis), to create a table with the mean value of field X in layer A. Specify the Case field to be the ID field that relates layer A to layer B.
  2. Use Join Field (Data Management), to permanently join the mean value field from the result of step 1 to layer B.

Try it out interactively in ArcToolbox first, then in the Results window, right-click the results for each of the two steps and click "Copy As Python snippet", and paste them into a new Python script. Tweak as needed (read in parameters and assign to variables, use variables in the tool arguments instead of hard-coding them, etc).

Here is an example workflow, which hopefully you will find can be applied to many other problems.

Data description:
I have a point feature class named atlantic_hurricanes_2000 (from the ArcObjects SDK sample data) that has many points recording windspeed, pressure, etc., along the path of each hurricane from the 2000 hurricane season:

I created a polyline feature class from it for the purposes of demonstration (each line is a separate hurricane track). The only meaningful attribute on the polyline layer, EVENTID is the name of the hurricane which will serve as an ID field that relates back to the point feature class:

Problem statement: The point feature class has a WINDSPEED field recording the wind speed at each point of a given hurricane track. I want to take the mean WINDSPEED value of all the points for each track in the point feature class and assign it to each polyline feature by adding a field.


  1. I used Summary Statistics as follows:

    Which produced this table:

  2. I then used Join Field as follows:

Final result:

Python snippet output:

arcpy.Statistics_analysis("C:/GISData/test.gdb/atlantic_hurricanes_2000","C:/GISData/test.gdb/atlantic_hurricanes_2000_average_windspeed","WINDSPEED MEAN","EVENTID")
  • thanks thats great. i turned the whole thing including my other processes into a model but when i export it as a python script and run it i get an error gp is not defined? – user4644 Oct 28 '11 at 13:59
  • Please edit your original question to include the script and error message. – blah238 Oct 28 '11 at 15:42
  • Or better yet, ask a new question since I anticipate the problem being something specific to the "ModelBuilder to Python" step. – blah238 Oct 28 '11 at 15:56

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.