kg76

arcpy.da.UpdateCursor to replace attribute field values based on other field values

Discussion created by kg76 on Mar 21, 2013
I have a file geodatabase that stores accuracy information in a few different ways depending on when the data was collected and what software was being used at the time (Terrasync vs. GPS Analyst vs. Positions). I've come up with a script to "zero out" legacy accuracy data when a new GPS location is taken for a given record. But, as I'm very new to Python, my script is only written for one feature class and I'd like it to work on all of the feature classes in my geodatabase. I tried using arcpy.ListFeatureClasses() at one point but I think I got an error. Anyway, here's what I have. Can anyone suggest how I can adapt this to work for all of my feature classes?


import arcpy

#Define a workspace

arcpy.env.workspace = r"C:\Users\KGaiz\Desktop\Archaeology_GDB\FLAG_Area_Archaeology.gdb"

#Assign variable featureclass

featureclass = r"C:\Users\KGaiz\Desktop\Archaeology_GDB\FLAG_Area_Archaeology.gdb\WACA\WACA_Site_Datum"

#Assign variable fields

fields =("EST_ACCURACY", "MAX_PDOP", "MAX_HDOP", "VERT_PREC",
"HORZ_PREC", "UNFILT_POS", "FILT_POS", "SOURCE", "SRC_DATE",
"DATAFILE")

#Create Update Cursor for feature class [UpdateCursor(in_table,
#field_names, {where_clause}, {spatial_reference},
#{explode_to_points}, {sql_clause})]


with arcpy.da.UpdateCursor(featureclass, fields) as cursor:
    #For each row, evaluate the EST_ACCURACY (index 0) value and
    #update the MAX_PDOP (index 1), MAX_HDOP (index 2), VERT_PREC
    #(index 3), HORZ_PREC(index 4), UNFILT_POS (index 5), FILT_POS
    #(index 6), SOURCE (index 7), SRC_DATE (index 8), and DATAFILE
    #(index 9) fields.
    for row in cursor:
        if (row[0] > 0 and row[0] <> "<Null>"):
            row[1] = 0
            row[2] = 0
            row[3] = 0
            row[4] = 0
            row[5] = 0
            row[6] = 0
            row[7] = "<Null>"
            row[8] = "<Null>"
            row[9] = "<Null>"

        cursor.updateRow(row)


Thanks,
Kerry

Outcomes