I have a number of tables that contain known values in a field. For example, I have a soil type table with one field in it. That field contains a list of known soil types. I have another table that has a list of known vegetation types. I have various other tables that contain lists of other known types of other data. What I want to do is:
Read in each table, do a cursor search and add the values to a list via
tableList.append
Now that I have built each list, I want to compare the values from a separate feature class table to the known values in the list I have just created using
if row.SOIL_TYPE in SoiltableList:
In order to do this, I need to reset the workspace I guess, because you cannot set a path parameter for listing data in any of the arcpy Listing methods.
env.workspace = r"C:\BASE_TABLES.gdb" SoiltableList = [] VegtableList = [] for table in arcpy.ListTables(): if table == "SOIL_TYPE": for row in arcpy.SearchCursor(table) SoiltableList.append(row.SOIL_TYPE) if table == "VEG_TYPE": for row in arcpy.SearchCursor(table) VegtableList.append(row.VEG_TYPE) # more iterations of table # Reset workspace env.workspace = r"C:\TEST_GDB.gdb" for fc in arcpy.ListFeatureClasses(): if fc == "SOIL_FEATURECLASS": for row in arcpy.SearchCursor(fc): if row.SOIL_TYPE in SoiltableList: print "YES" else: print "No" # More iterations of if/else logic to compare values from fields from various feature classes to the known values in the list I built.
The 2 questions I have are:
- Do I need to reset the workspace the way I did above? is there a better way of doing this or is what I am doing completely acceptable?
- Does my code make sense? Am I over complicating what I am trying to do? I though that maybe I would define a function or 2 to simplify the code, but I'm still in the process of figuring out what else I want the code to do.
Thanks for any suggestions.
Mike
SOIL_TYPE
andVEG_TYPE
? Those look more like field names than table names. What exactly are you trying to accomplish?