Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

arcpy.da cursor : iteration not started

$
0
0

I am trying to convert cursors written in 10.0 to use the new arcpy.da module in 10.2.1. If I step through the code in debug mode, it steps into the for loop; however, when I attempt to run the code I get an exception : iteration not started

code for 10.0

for row in updateCursor:
    if row.getValue("STREET_NUMBER_PREFIX") in ['N', 'S', 'W']:
        row.setValue("STREET_DIR_PREFIX",  row.getValue("STREET_NUMBER_PREFIX"))
        row.setValue("STREET_NUMBER_PREFIX", None)

code for 10.2.1

with arcpy.da.UpdateCursor(civicAddress, flds) as rows:
    for row in rows:
        if row[0] in ['N', 'S', 'W']:
            row[1] = row[0]
            row[0] = None

What can I do to solve my problem? I have quite a few code blocks as above that deal with specific logic cases. Many thanks

EDIT: here is the full code for that section, maybe it will help:

flds = ("STREET_NUMBER_PREFIX", "STREET_DIR_PREFIX", "STREET_NUMBER_SUFFIX", "CIVIC_ID")
flds2 = ("CIVIC_ID", "UNIT_NUMBER")
log.information ("Creating cursors...")
insertCursor =  arcpy.da.InsertCursor(subAddress, flds2)
#row = []

with arcpy.da.UpdateCursor(civicAddress, flds) as rows:
    for row in rows:
        if row[0] in ['N', 'S', 'W']:
            row[1] = row[0]
            row[0] = None

        if row[2] in ['N', 'S', 'W']:
            row[1] = row[2]
            row[2] = None

        if row[2] in unitLst:
            newrow = insertCursor.newRow()
            newrow[0] = row[3]
            newrow[1] = row[2]
            row[2] = None
            insertCursor.insertRow(newrow)


        if row[0] in unitLst:
            newrow = insertCursor.newRow()
            newrow[0] = row[3]
            newrow[1] = row[0]
            row[0] = None
            insertCursor.insertRow(newrow)

        try:
            if re.match("[0-9][A-Z]", row[0]) or re.match("[0-9][0-9][A-Z]", row[0]) or 
            re.match("[A-Z][0-9]", row[0]) or re.match("[A-Z][0-9][0-9]", row[0]):
                newrow = insertCursor.newRow()
                newrow[0] = row[3]
                newrow[1] = row[0]
                row.setValue("STREET_NUMBER_PREFIX", None)
                row[0] = None
                insertCursor.insertRow(newrow)
        except:
            pass

        try:
            if re.match("[0-9][A-Z]", row[2]) or re.match("[0-9][0-9][A-Z]", row[2]) or 
            re.match("[A-Z][0-9]", row[2]) or re.match("[A-Z][0-9][0-9]", row[2]):
                newrow = insertCursor.newRow()
                newrow[0] = row[3]
                newrow[1] = row[2]
                row[2] = None
                insertCursor.insertRow(newrow)
        except:
            pass

        try:
            if row[0].isdigit():
                newrow = insertCursor.newRow()
                newrow[0] = row[3]
                newrow[1] =  row[0]
                row.setValue("STREET_NUMBER_PREFIX", None)
                row[0] = None
                insertCursor.insertRow(newrow)
        except:
            pass

        try:
            #if row.getValue("STREET_NUMBER_SUFFIX").isdigit():
            if row[2].isdigit():
                newrow = insertCursor.newRow()
                #newrow.setValue("CIVIC_ID", row.getValue("CIVIC_ID"))
                newrow[0] = row[3]
                # newrow.setValue("UNIT_NUMBER", row.getValue("STREET_NUMBER_SUFFIX"))
                newrow[1] = row[2]
                #row.setValue("STREET_NUMBER_SUFFIX", None)
                row[2] = None
                insertCursor.insertRow(newrow)
        except:
            pass

    rows.updateRow(row)
    del row
    del newrow
    del rows

Viewing all articles
Browse latest Browse all 767

Trending Articles