Select to view content in your preferred language

UpdateCursor problems with AddJoin

571
2
09-27-2011 01:12 PM
MathewCoyle
Honored Contributor
Background: When trying to improve speed of script, changed JoinField tool to AddJoin tool. The former was taking over 3 hours to join, the later a few seconds.

Later in the script when trying to create an UpdateCursor I get an error when using the temporary join (AddJoin).

Previously ran fine with permanent join (JoinField). Or when exported after temporary join.

Is this normal or a bug? Does anyone know of a faster way to process joined data?

Edit:
Line giving error:
rows = arcpy.UpdateCursor(calc_table)

Error received:
Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    rows = arcpy.UpdateCursor(calc_table)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 825, in UpdateCursor
    return gp.updateCursor(*args)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 362, in updateCursor
    self._gp.UpdateCursor(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.)
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
What are you attempting to update with the 'UpdateCursor' function?  The field names will be different with a temporary join.  Can you post the rest of your code?
0 Kudos
MathewCoyle
Honored Contributor
Tableview to Tableview temporary join. Here is the code below in the offending function. I tried playing around with table names in field references to try to get it to work, but to no avail. The script does not even step into the cursor, fails hard on {rows = arcpy.UpdateCursor(calc_table)} line.

def pieces():
    """ Calculates CON_PIECE, DEC_PIECE, CON_VOL and DEC_VOL fields """
    """ ~3.5 hours total, ~3 hours for join """
    vol_tab = "strata_volumes"
    joinField = "STRATA"
    arcpy.AddIndex_management(calc_table, "STRATA", "STRA_IND")
    strata_table = arcpy.MakeTableView_management(vol_tab)
    print "Starting join at "+datetime.datetime.now().strftime("%H:%M:%S")
    #Syntax
    #AddJoin_management (in_layer_or_view, in_field, join_table, join_field, {join_type})
    arcpy.AddJoin_management(calc_table, joinField, strata_table, joinField)
    #arcpy.JoinField_management(calc_table, joinField, vol_tab, joinField)
    print "Done join at "+datetime.datetime.now().strftime("%H:%M:%S")
    #decid_list = ["Aw","Pb","Bw"]
    #con_list = ["Sw", "Sb", "Fb", "Pl", "Pj", "Lt"]
    species = [
    ("C","Fb","FB_STEMS"),("C","Sw","SW_STEMS"),("C","Pj","PJ_STEMS"), # 0,1,2
    ("C","Pl","PJ_STEMS"),("C","Lt","LT_STEMS"),("C","Sb","SB_STEMS"), # 3,4,5
    ("D","Bw","BW_STEMS"),("D","Aw","AW_STEMS"),("D","Pb","PB_STEMS")  # 6,7,8
    ]
    sp_fields = [("SP1","SP1_PER"),("SP2","SP2_PER"),("SP3","SP3_PER"),
    ("SP4","SP4_PER"),("SP5","SP5_PER")]
    rows = arcpy.UpdateCursor(calc_table)
    spec_count = 0
    sp_count = 0
    row_count = 0
    for row in rows:
        con = float(0)
        dec = float(0)
        dec_p = float(row.getValue("avi_copy.DEC_PER"))
        for sp in sp_fields:
            sp_type = row.getValue("avi_copy."+sp[0])
            spp_f = float(row.getValue("avi_copy."+sp[1]))
            if spp_f > 0:
                for spec in species:
                    stem_f = row.getValue(strata_table+"."+spec[2])
                    if spec[0] == "C" and dec_p < 10.0 and sp_type == spec[1]:
                        con = con + (spp_f * stem_f) / (10 - dec_p)

                    elif spec[0] == "D" and dec_p > 0.0 and sp_type == spec[1]:
                        dec = dec + (spp_f * stem_f) / dec_p
                    else:
                        continue
            else:
                continue

        vol_ha = row.getValue(strata_table+".VOL_HA")
        con_vol = 0
        dec_vol = 0
        if dec_p == 10:
            con_vol = vol_ha * 0.03
            dec_vol = vol_ha - con_vol
        elif dec_p == 0:
            dec_vol = vol_ha * 0.03
            con_vol = vol_ha - dec_vol
        elif dec_p > 0 and dec_p < 10:
            dec_vol = vol_ha * (dec_p / 10)
            con_vol = vol_ha - dec_vol

        row.avi_copy.con_volha = con_vol
        row.avi_copy.dec_volha = dec_vol
        row.avi_copy.con_piece = con
        row.avi_copy.dec_piece = dec

        rows.updateRow(row)
0 Kudos