Select to view content in your preferred language

Best/fastest way to delete all FC's in a geodatabase?

3654
7
10-10-2012 11:55 PM
StefanHaglund1
Esri Contributor
Hi All,

This is a problem I run into from time to time and have never found a good solution for.

Right now I am using Modelbuilder to create a workflow that creates a lot of intermediate data. Likely because I have an iterator in the model, only the last FC (marked as intermediate) that the iterator comes across is deleted from my scratch.gdb. I would like to clean out my scratch.gdb, but not remove the geodatabase itself, after my model is run. There are a couple of ways to do this but all that I'm aware of are time-consuming. I'ver tried Iterate Feature Classes and Delete_management, but both just takes too long time.

In other workflows, I've come across the same problem of cleaning out a gdb without removing it where I've had several thounds of FC's and it simply takes too much time.

Any ideas...?

Thanks!
0 Kudos
7 Replies
MarcinGasior
Frequent Contributor
ArcGIS help on Deleting intermediate data claims that intemediate data is deleted automatically when a model is run as a model tool or from Python but is preserved when a model is run in ModelBuilder.
In ModelBuilder there's specific command (Menu -> Delete Intermediate Data) to delete this data.

Moreover, consider marking intermediate data as Managed what ensures that ModelBuilder manage data.

There's one more option for intermediate data - in_memory workspace.
You can use this temporary workspace to store vector and tabular data which is not written to disc but stored in computer memory.
To use it just type in_memory instead of geodatabase path (eg. in_memory\FeatureClass).
0 Kudos
StefanHaglund1
Esri Contributor
Thank's m.gasior!

I run my model as a tool, so it intermediate data should be deleted. One problem here seems to be that I am using an iterator, then only the last fc iterated is deleted, the previous once are still there.

I'll try the in_memory workspace in this case, I  probably have a small enough amount of data that it should work ok. But for other workflows, that's not possible due to the amount of data. So the question remains, what is the best way to delete all FC's?
0 Kudos
AlexeyTereshenkov
Deactivated User
Hi Stefan,

I did not estimate the performance of running the Iterate FC iterator for deletion of feature classes but you might try using Python arcpy 10.1 (did you use 10.0?) module for deleting your feature classes to see if it will go faster:

To delete feature classes within a certain feature dataset:
import arcpy
arcpy.env.workspace = r"C:\Temp\TestGeodatabase.gdb\featureDataset"
for objFeatureClass in arcpy.ListFeatureClasses():
    arcpy.Delete_management(objFeatureClass)


To delete feature classes within a geodatabase:
import arcpy
arcpy.env.workspace = r"C:\Temp\TestGeodatabase.gdb"
for objFeatureClass in arcpy.ListFeatureClasses():
    arcpy.Delete_management(objFeatureClass)


If you have thousands of feature classes written to disk and you will not need them after running the model, you might consider deleting the whole geodatabase and creating a new one (deleting a geodatabase with all data in in theoretically should go faster then looping through all individual feature classes).

And well, if you deal with *big* amounts of data, consider getting more RAM for your PC to be able to take advantage of in_memory workspace (I use it heavily nearly for every scenario applicable) 🙂 or be more patient after running the model when your intermediate data is being deleted 🙂
0 Kudos
StefanHaglund1
Esri Contributor
Hi Alex,

I tried that same code (on 10.1) before and ran it again now to clock it. For a FGDB with 129 FC's in it, it takes more than three minutes when I run it from Python-window in ArcMap, and 1.15 when run from IDLE. Still too long:)

I will go with in_memory more often and delete and recreate the entire gdb when I have to, although that just seems like a weird workflow.
Patience isn't my strong side;) 

Thank's!
0 Kudos
DaleHoneycutt
Deactivated User
This is timely -- I was developing a model with iterators yesterday and discovered what you did: only the last feature class produced as part of the iterator is deleted (if marked intermediate).  I actually didn't want anything to be deleted--I had accidentally marked the variable as intermediate.  I only saw this behavior on 10.0, not 10.1. 

Anyway, this isn't your issue--you want everything produced by the iterator to be deleted if the variable is intermediate.  We'll look to see if it's possible to implement this... I suspect it's very tricky. 

In the meantime, I'd go with deleting the entire scratch geodatabase.  In a model, you could use the Create File Geodatabase tool to create a new one after deleting the old one.
0 Kudos
StefanHaglund1
Esri Contributor
Dale,

Good to know you see the same issue. I thought of making a support-case out of it but now it sounds like it's in the loop in Redlands anyway.

Also, I'd really like to see a "Clean Geodatabase" tool, where I could choose to delete everything in it except the schema. I realize I could you use the Copy_management and Rename_management if I want to keep the schema but it would be nice to have simple, quick way of doing this.
0 Kudos
DaleHoneycutt
Deactivated User
A "clean geodatabase" tool is a cool idea -- leave the schema intact, just remove all the records.  (BTW: You can probably use a combination of Export XML Workspace Document and Import XML Workspace Document to do this.)

Anyway, for ideas like this, be sure to visit the Ideas site and log a suggestion.
0 Kudos