3

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)").

  • 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
2

I would try doing this using the Select (Analysis) tool:

Extracts features from an input feature class or input feature layer, typically using a select or Structured Query Language (SQL) expression and stores them in an output feature class.

in batch mode:

To use batch, right-click a tool and click Batch. This opens the batch dialog box with one row of the batch grid

5

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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