In this article you will learn how to delete empty features in a spatial database using Python in a very simple way.
Once the control of your data is done, as well as all the pertinent verifications in the database (GDB), it may be necessary to delete some features contemplated in the data model, either because it was not necessary to fill them, they do not apply to the area of study, or they exceed the technical terms of reference, next I present you how to delete elements in a database:
How to delete manually (File geodatabase .gdb or Personal geodatabase .mdb).
Option 1:
Drag the feature you want to delete to a blank ArcMap file (a). Press the “Search” button (b), from the “Standard” toolbar, in the displayed tab type the word “Delete” (c), press the first link which will open the “Delete” tool (d), and drag the layer to the tool and press OK (e). This will delete the selected element from your hard drive.
Option 2:
Press the “Catalog” button (a), from the “Standard” toolbar, in the displayed tab press the “Connect To Folder” button (b) and browse to the path where the information to be deleted is stored (If you have not previously associated the containing folder to ArcCatalog). Select the item to be deleted and right click and press the “Delete” option (c). This will delete the selected item from your hard drive.
Deleting one or two items within a database is easy, but if the number increases, it can become a tedious task, I propose the following automated alternative using Python code. If you want to delete all the elements (Feature or Shapefile, and tables) empty in a database, follow these steps:
How to delete with python (File geodatabase .gdb or Personal geodatabase .mdb).
Step 0: Make a backup of the database (You never know what can happen).
Step 1: Identify the path that represents the database to examine in the operating system explorer.
Step 2: Open ArcMap (A blank mxd file).
Step 3: Open the Python window in the Standard toolbar.
Step 4: Copy the following code into notepad.
Step 5: In line #03, replace the text C:\EJEMPLO\EJEMPLO.GDB with the path to the database, including its name with its extension, as in the code example (keep the quotation marks).
Step 6: Copy the modified code into the Python window and press the Enter or Enter key twice.
NOTES:
- This script has always given me problems using very long paths so I recommend working in a folder at the root of a storage drive (a).
Well, this way you will have deleted the empty features and tables inside a database, if you are interested in making a list of the empty elements to verify them before deleting them, I recommend you to go through my article “PYTHON GIS / EXCEL - How to list empty elements in the database”.
I hope you enjoyed this article, soon I will upload a video explaining the procedure that you can consult in this blog. Save my blog among your favorite links, I will be uploading many more tricks of this style, remember that you can send me your concerns on the contact page or leave your comment, I will be attentive to respond.




