After a bit of research and utilizing my very limited programming experience, I recently patched together the python code shown below:
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Set the overwrite to true...
gp.overwriteoutput = 1
# The file to be updated...
fc = r"C:\Documents and Settings\Andrew\Desktop\NIDIS\Project\HUC12_CRB_streamflow_with_fields.shp"
#Create update cursor for feature layer and point to first record
updateCursor = gp.UpdateCursor(fc)
#Cursor for tracing upstream
traceCursor = gp.UpdateCursor(fc)
#Move cursor to first record
row = updateCursor.Next()
while row:
#initialize huc_id
huc_id = "1"
#Get gauge value
gauge_assign = str(row.getvalue("FIRST_ABCC"))
#Get DS HUC value
huc_ds = str(row.GetValue("HU_12_DS"))
#determine if poly has gauge assigned already
if gauge_assign != "":
row = updateCursor.next()
#if gauge not assigned, trace downstream
else:
while huc_id != huc_ds:
traceRow = traceCursor.Next()
huc_id = str(traceRow.getvalue("HUC_12"))
#exception for no DS gauges
if huc_ds == "":
huc_id = "none"
huc_ds = "none"
#If there are no DS gauges, assign value of "none"
if huc_id == "none":
gauge_assign = "none"
else:
gauge_assign = str(traceRow.GetValue("FIRST_ABCC"))
traceRow.reset()
row.SetValue("FIRST_ABCC", gauge_assign)
row = updateCursor.next()
del updateCursor, traceCursor, gp
This code is intended to:
1: determine if the "FIRST_ABCC" field is empty (if not, go to next feature)
2: if "FIRST_ABCC" field is not empty, trace "downstream" using the "HU_12_DS" field which corresponds to the "HUC_12" field of the next "downstream" feature until a feature is found with a "FIRST_ABCC" field that isn't empty - assign this value to the "FIRST_ABCC" field of the original feature being traced from
3: move on to next feature - repeat process for all features in the layer
The code appears to run without errors but doesn't appear to do anything. Seeing as my experience with python spans all of the past 3 days, I'm assuming that there is something relatively straightforward that I am missing. Can someone with some more experience scripting in python point me in the right direction? Thanks.
Cheers,
Andrew Barney
Research Technician
Utah Water Research Laboratory