Script to sum values from one field and place them into another field ARCGIS

31 May

Hi guys,

Today I had to sum the values from a field from a raster file and write the output into another. Despite you’ll think that Arcgis would have a tool to do this in a simple way, I found out that this was not necessarily the case :p

I wrote an script in python to solve this. I hope you find it useful.

What the script does is to sum the values from a field writing the result into another field in the table.

You can copy this and add it into your toolbox 🙂

The arguments that are necessary are:

#(1) table = table containing the field you want to sum

#(2) fieldtosum= the field that you are going to sum

#(3) fieldwrite= the field in which the sum is going to be writen

#Script
import arcgisscripting, sys
gp = arcgisscripting.create()
table = sys.argv[1]
fieldtosum = sys.argv[2]
fieldwrite = sys.argv[3]

rows = gp.SearchCursor(table)
row = rows.Next()
p = 0.0
while row:
p += row.getvalue(fieldtosum)
print p
row = rows.next()
#calculate field
gp.calculatefield(table,sys.argv[3],float(p),”PYTHON”)
#End——-

Very soon I’ll be writing about how to do a series of variants of visibility analysis such as “Directional Viewsheds” and “Higuchi Viewsheds” that can be very useful in archaeology 🙂

Advertisements

One Response to “Script to sum values from one field and place them into another field ARCGIS”

  1. johnwallx June 9, 2012 at 4:50 pm #

    Thank you for sharing this! Have you used GitHub at all? It’s fairly useful for sharing, storing, and getting comments on code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: