populate a field in a raster dataset based on the total SUM of another field

413
4
05-03-2011 05:25 PM
ThilinaSurasinghe
New Contributor
I have multiple land-use land-cover raster layers, of which the attribute tables have a field on the total area coverage by different land-use type (field name is AREA). My goal is to have another column populated with the percentage area coverage for the each land-use land cover type in the rate dataset.
I tried to do this by populating another column in the same attribute table with the summation (total summation, not cumulative summation) of AREA. If I could get this column, I can write a simple expression in the "calculate field tool" to calculate the percentage coverage.
I have nearly 100 raster layers with different geometric shapes so that I need to do this via model builder. Since this is an iterative process, calculating the column sum by the "calculate statistics tool" in not useful either.
Does anyone have a tool or a python script for this? I am using ArcGIS 10.
Thanks.
Thilina
Tags (2)
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor
Here is an example on how you can sum the Area field into a new field (SUM_Area).  From there you can calculate the percentage.

list = []

lstRasters = arcpy.ListRasters("*")
for raster in lstRasters:
    rows = arcpy.SearchCursor(raster)
    for row in rows:
        list.append(row.Area)
    S = sum(list)
    arcpy.CalculateField_management(raster, "SUM_Area", S)
    list = []

del row, rows
0 Kudos
KhanKamruzzaman
New Contributor
Hi JSkinn3,
I have a similar kind of question like tdilan1980 . I want summarise a field of my table and update the output into another field.
I know how to do in python window but don�??t know how to do it in �??Filed Calculator window in ArcMap table.
Specially, how do you write a code for "arcpy.SearchCursor" function in their?

Any help would be highly appreciable?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Below is an example on how you can do this using the Field Calculator.  Be sure to check 'Python' at the top and 'Show Codeblock'.  Under 'Pre-logic Script Code' enter the following:

def update():
  import arcpy
  list = []
  rows = arcpy.SearchCursor(r"C:\data\Parcels")
  for row in rows:
    list.append(row.AREA)
  S = sum(list)
  del row, rows
  rows = arcpy.UpdateCursor(r"C:\data\Parcels")
  for row in rows:
    row.AREA2 = S
    val = row.AREA2
  del row, rows
  return val


Then, under the second block enter:

update()
0 Kudos
KhanKamruzzaman
New Contributor
Hi JSkinn3
Excellent!!. It works perfectly. Thanks a lot.
0 Kudos