This is my first adventure into Python scripting so excuse my ignorance. I am trying to loop through FC's in a GDB and select by an attribute then copy those feature classes into the GDB. Below is my script so far. Where my question lies is, in the 'SelectLayerByAttribute' process how do I specify the feature layer that was created in the previous step as the FC to do the selecting from? See where my question marks are below, that is where im unsure import arcpy from arcpy import env env.workspace = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb" # Local Variables GDB = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb" # Get a list of all feature classes fcList = arcpy.ListFeatureClasses() # Loop through each feature class in the GDB for fc in fcList: # Put in error trapping in case an error occurs when running tool try: # Make a layer from the feature classes arcpy.MakeFeatureLayer_management(fc, fc + '_LYR') # Select features by attribute arcpy.SelectLayerByAttribute_management(" ?????????", "NEW_SELECTION", "\"Source\" = 'GAI'") # Copy selected features to GDB arcpy.CopyFeatures_management(" ???????", GDB)
# Make a layer from the feature classes fl = arcpy.MakeFeatureLayer_management(fc, fc + '_LYR') # Select features by attribute fl_sel = arcpy.SelectLayerByAttribute_management("fl", "NEW_SELECTION", "\"Source\" = 'GAI'") # Copy selected features to GDB arcpy.CopyFeatures_management("fl_sel", GDB)
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.