Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have several hundred geodatabase feature classes which all have the exact same fields. I need to go through each of those feature classes and delete any records which match an SQL query (the same SQL query can be applied to all the feature classes). Alternatively, I could export them all to new feature classes, keeping the records I want. In ArcCatalog I can export them singly using an SQL query to specify which records get exported, but the SQL statement option isn't available when you want to export multiple layers simultaneously (using "Feature Class to Geodatabase (multiple)").

share|improve this question
1  
What I ended up doing was using the "Feature Class to Feature Class (single)" tool in batch mode, that let me use an SQL query for each feature class. –  Dan C Sep 23 '11 at 20:28
    
That was going to be my advice too - although I was instead testing the Select tool in batch mode. –  PolyGeo Sep 23 '11 at 21:48
    
This would have been my way; simply copy over the columns you do want to a new FC, less code and less drama. Sometimes working with cursors can be laborious. –  Hairy Sep 26 '11 at 6:53
add comment

1 Answer

One way to automate the processing of this would be with Python by working through a list of the feature classes, and the using an updatecursor/deleteRow statement to delete the unneeded records.

import arcpy

workspace = r"c:\yourworkspace\yourgeodatabase.gdb"  #assuming file geodatabase
arcpy.env.workspace = workspace

#Part 1 -- create list of feature classes in your geodatabase...
#assuming all featureclasses within the geodatabase are of interest for the query -- otherwise specify a wildcard below

featureclasslist = arcpy.ListFeatureClasses()

#now run a loop on feature classes in the list
for featureclass in featureclasslist:


 #Part 2 -- deleting the records specified in your sql query. There are two approaches:

 # option1:
    your_query = " \"yourfield\" = 'your_value' "  #enter your sql query here

    rows = arcpy.UpdateCursor(featureclass, your_query)
    for row in rows:
        rows.deleteRow(row)

    # or option 2

    rows = arcpy.UpdateCursor(featureclass)
    for row in rows:
        if row.getValue("Yourfield") == 'your_value':
            rows.deleteRow(row)

More here on listing featureclasses: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001n000000

and on the updatecursor/deleteRow statement: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.