I currently have a script that will select and delete all the values less than 0.1 in a column. The script below works, however it specifies a specific .shp, I want to batch this so it runs through all the shapefiles in a geodatabase
import arcpy
arcpy.SelectLayerByAttribute_management("Sr90_contour","NEW_SELECTION",'"Contour" < 0.1')
arcpy.DeleteFeatures_management("Sr90_contour")
1 Answer 1
You can specify the GDB as your workspace and then use the arcpy.ListFeatureClasses()
function to get all the names of the features in that GDB:
import arcpy
arcpy.env.worskapce = r'C:\path\to\my.gdb'
for fc in arcpy.ListFeatureClasses():
arcpy.MakeFeatureLayer_management(fc, "lyr")
arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", '"Contour" < 0.1')
arcpy.DeleteFeatures_management("lyr")
Note that this will only work if all your feature classes have the Contour
field.
-
Thanks, However when I run that I get the following error......... runtime error Traceback (most recent call last): File "<string>", line 6, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 7221, in SelectLayerByAttribute raise e ExecuteError: The value cannot be a feature class ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer.JHR– JHR2019年08月13日 15:24:11 +00:00Commented Aug 13, 2019 at 15:24
-
You need to create an in-memory feature layer for every feature class first before making a selection on it. See heremdholl6188– mdholl61882019年08月13日 15:32:48 +00:00Commented Aug 13, 2019 at 15:32
-
@JHR See the edit I just made to the question taking into accout the comment from mdholl6188. Also, delete your answer, as it does not really answer your question but is rather a comment or edit.Marcelo Villa– Marcelo Villa2019年08月13日 16:07:15 +00:00Commented Aug 13, 2019 at 16:07
Explore related questions
See similar questions with these tags.