AnsweredAssumed Answered

How do you compare a list of records in a table with a list of feature classes, populating the table with the feature class records counts?

Question asked by RP.CObb on Sep 26, 2019
Latest reply on Sep 26, 2019 by RP.CObb

Hi,

 

So I have a relatively simple script that is basically a complete list of feature classes in a database and I was wondering how you would compare that list of feature classes to the list of records in a table.

 

The other thing is, if there is a match between the list of feature classes and the table, to have the table populate with the record count of the matching feature class. I have a rough script that has both the list of the feature classes in a database and the list from the table, as well as the counts for each feature class. The other issue is that the names aren't the exact same but are similar.

 

So I am trying to first figure out how to compare the list of feature classes to the list of records in the table. I think once I can get that then the rest should be relatively simple to do.

import arcpy

#set parameters
inputTable = r'G:\MyThings\Test\NewTest3\StormLoad.gdb\Stormload_Table'#arcpy.GetParameterAsText(0)
select_databases = r'G:\MyThings\Test\NewTest4\StormLoad.gdb'#arcpy.GetParamterAsText(1)
#select_fields_toUpdate = arcpy.GetParameterAsText(2)
input_value = '2'#arcpy.GetParameterAsText(3)

arcpy.env.workspace = select_databases

#Get list of field names
field_names = [f.name for f in arcpy.ListFields(inputTable)]

#Identify feature class and database field name
fcdb_name_field = field_names[1]

#Select the field names to populate
select_field_names = field_names[2:]
   
datasetList = arcpy.ListDatasets('*','Feature')

#List feature classes
def fcsInDS():
    for dataset in datasetList:
        arcpy.env.workspace = dataset
        fcList = arcpy.ListFeatureClasses()
    return fcList

fcsInDB = arcpy.ListFeatureClasses()

fcs = fcsInDS() + fcsInDB
for fc in fcs:
    fc_ReCount = arcpy.GetCount_management(fc)
    print '{0} has a record count of {1}'.format(fc, fc_ReCount)

    with arcpy.da.UpdateCursor(inputTable, field_names) as cursor:
        for row in cursor:
            if row[1] in fc:
                row[2] = input_value #
                cursor.updateRow(row)

 

I also noticed that when it loops through the list of combined lists, that it errors out with the feature classes in the database as either non existent or supported. I tried making a couple of adjustments to this script but it returns errors.

 

I would greatly appreciate any assistance with this.

 

-Robert

Outcomes