Newby Needs Help with Python code

Nally Kaunda-Bukenya nkaunda at yahoo.com
Wed Sep 1 03:29:05 EDT 2010


  
Dear Python experts, 
I hope someone can help me. I am new to Python and trying to achive the 
following:
1)      I would like to populate the Tot_Ouf_Area field with total area of each 
unique outfall_id (code attempted below,but Tot_Ouf_Area not populating)
2)      I would also like to get the user input of Rv ( each landuse type will 
have a specific Rv value). For example the program should ask the user for Rv 
value of Low Density Residential (user enters 0.4 in example below and that 
value must be stored in the Rv field), and so on as shown in the 2nd table 
below…
Below is my original table (comma-delimited)
"OBJECTID","OUTFALL_ID","LANDUSE","AREA_ACRES","Rv","Tot_Outf_Area"
16,"ALD06001","High Density Residential",6.860922,0.000000,0.000000
15,"ALD06001","General Commercial",7.520816,0.000000,0.000000
14,"ALD05002","Low Density Residential",7.255491,0.000000,0.000000
13,"ALD05002","Forest",37.090473,0.000000,0.000000
12,"ALD05001","Low Density Residential",16.904560,0.000000,0.000000
11,"ALD05001","Forest",84.971686,0.000000,0.000000
10,"ALD04002","Urban Open",1.478677,0.000000,0.000000
9,"ALD04002","Transportation",0.491887,0.000000,0.000000
8,"ALD04002","Low Density Residential",25.259720,0.000000,0.000000
7,"ALD04002","Forest",0.355659,0.000000,0.000000
6,"ALD04001","Recreational",0.013240,0.000000,0.000000
5,"ALD04001","Low Density Residential",34.440130,0.000000,0.000000
4,"ALD04001","Forest",10.229973,0.000000,0.000000
3,"ALD03002","Low Density Residential",23.191538,0.000000,0.000000
2,"ALD03002","Forest",1.853920,0.000000,0.000000
1,"ALD03001","Low Density Residential",6.828130,0.000000,0.000000
21,"ALD06001","Water.dgn",0.013951,0.000000,0.000000
20,"ALD06001","Urban Open",10.382900,0.000000,0.000000
19,"ALD06001","Transportation",2.064454,0.000000,0.000000
18,"ALD06001","Recreational",0.011007,0.000000,0.000000
17,"ALD06001","Low Density Residential",0.752509,0.000000,0.000000
 
Below is my desired output table (comma delimited):
"OBJECTID","OUTFALL_ID","LANDUSE","AREA_ACRES","Rv","Tot_Outf_Area"
16,"ALD06001","High Density Residential",6.860922,0.000000,27.606562
15,"ALD06001","General Commercial",7.520816,0.000000,27.606562
14,"ALD05002","Low Density Residential",7.255491,0.400000,44.345966
13,"ALD05002","Forest",37.090473,0.300000,44.345966
11,"ALD05001","Forest",84.971686,0.300000,101.876247
12,"ALD05001","Low Density Residential",16.904560,0.400000,101.876247
10,"ALD04002","Urban Open",1.478677,0.000000,27.585945
9,"ALD04002","Transportation",0.491887,0.000000,27.585945
8,"ALD04002","Low Density Residential",25.259720,0.400000,27.585945
7,"ALD04002","Forest",0.355659,0.300000,27.585945
6,"ALD04001","Recreational",0.013240,0.000000,44.683345
5,"ALD04001","Low Density Residential",34.440130,0.400000,44.683345
4,"ALD04001","Forest",10.229973,0.300000,44.683345
3,"ALD03002","Low Density Residential",23.191538,0.400000,25.045460
2,"ALD03002","Forest",1.853920,0.300000,25.045460
1,"ALD03001","Low Density Residential",6.828130,0.400000,6.828130
21,"ALD06001","Water.dgn",0.013951,0.000000,27.606562
20,"ALD06001","Urban Open",10.382900,0.000000,27.606562
19,"ALD06001","Transportation",2.064454,0.000000,27.606562
18,"ALD06001","Recreational",0.011007,0.000000,27.606562
17,"ALD06001","Low Density Residential",0.752509,0.400000,27.606562
Below is my code so far for updating rows with total area (Tot_Ouf_Area):
 
#THE PROGRAM:
import arcgisscripting
gp=arcgisscripting.create()
gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb"
fc = "Outfalls_ND"
try:
    # Set the field to create a list of unique values    
        fieldname = "OUTFALL_ID"
        
    # Open a Search Cursor to identify all unique values
        cur = gp.UpdateCursor(fc)
        row = cur.Next()
        # Set a list variable to hold all unique values
        L = []
        # Using a while loop, cursor through all records and append unique
        #values to the list variable
        while row <> None:
            value = row.GetValue(fieldname)
            if value not in L:
                L.append(value)
            row = cur.Next()
            row.SetValue(Tot_Outf_Area, sum(row.AREA_ACRES)) #total area of each 
outfall=sum of all area 4 each unique outfallid
            cur.UpdateRow(row) #to commit changes
            row=cur.Next()
            print row.Tot_Outf_Area
        # Sort the list variable
        L.sort()
        # If a value in the list variable is blank, remove it from the list 
variable
        #to filter out diffuse outfalls
        if ' ' in L:
            L.remove(' ')
except:
    # If an error occurred while running a tool, print the messages
    print gp.GetMessages()
 
#Please Help!!!
#Esther


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100901/401c9011/attachment.html>


More information about the Python-list mailing list