AnsweredAssumed Answered

Feature Class to feature class failing on second iteration

Question asked by recurvata on Nov 20, 2014
Latest reply on Nov 21, 2014 by xander_bakker

I've got two feature classes, one with data for four counties, and one with data for just one of the counties. I extract data from these feature classes into new feature classes in other feature datasets via arcpy.FeatureClasstoFeatureClass. The calling code is the first code block below. The relevant code for extractFeatures() is in the second code block

The the new feature class names, and the expressions used to extract them, are in tables. However, although they seem identical,AllCounties runs fine, but Chatham fails with a 999999 Execute Error function. A typical expression would be something like "FCC" LIKE 'H1%'. I've printed out all the values and they seem correct. I don't see any essential difference between one run through the code and another.

Can anyone see what's going wrong here? Thanks.

 

 

# CALLING CODE
# tbls = dictionary of table name : feature dataset pairs
# extract features for all four counties
    sfc = 'AllCounties'
    tbls = {'BoundaryDefinitions' : 'Boundaries',
            'TransportationDefinitions' : 'Transportation',
            'HydroDefinitions' : 'Hydrology'}

    for k, v in tbls.iteritems():
        extractFeatures(k, sfc, v)

    # extract features for Chatham County only. 
    sfc = 'Chatham'
    tbls = {'BoundaryDefinitions' : 'ChathamBoundaries',
            'TransportationDefinitions' : 'Chathamransportation',
            'HydroDefinitions' : 'ChathamHydrology'}

    for k, v in tbls.iteritems():
        extractFeatures(k, sfc, v)

 

 

# in extractFeatures()
# get feature class name/extraction expression pairs
    tbl = os.path.join(targetGDB, tblnm)
    flds = ('Name', 'Definition') # field names in table
    defs = {}
    try:
        with arcpy.da.SearchCursor(tbl, flds) as rows:
            for row in rows:
                defs[row[0]] = row[1]   
    # print error message and return empty dictionary to prevent further processing
    except exception as e:
        s = '\n\tError: unable to retrieve values from {0}.\n\t{1}\n'
        print(s.format(tbl, e.message))
        defs = {}

    # data was returned from the definition table
    if defs:
        sds = 'Framework'
        src = os.path.join(targetGDB, sds, sfc)
        target = os.path.join(targetGDB, tds)

        for k, v in defs.iteritems():
            try:
                arcpy.FeatureClassToFeatureClass_conversion(src, target, k, v)
                print('\tExtracted {0} from {1} to {2}.'.format(k, sfc, tds))
            except Exception as e:
                s = '\tError: {0} not extracted. Halting extraction of {1} features.\n\t{2}'
                print(s.format(k, tds, e.message))
                break

Outcomes