3

I'm working on a script that will empty my SDE database of all data. How would I go about deleting features from feature classes using ArcPy?

I have an SDE connection created with a user that should have delete privileges. So far I've tried using the arcpy.DeleteFeatures_management from code and from the Delete Features toolbox in data management.

My DB has SDE feature datasets with SDE feature classes inside.

The Delete Features tool box errors out with:

ERROR 000732: Input Features: "Dataset Database Connections\Connection to sde.sde\User.MyFeatureDataset\User.MyFeatureClass" does not exist or is not supported.

The documentation is not really helping me. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000036000000

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 18, 2012 at 21:08
2
  • 2
    If you are not able to use the Delete Features in data management successfully it suggests to me that there is a permission problem. I would focus on getting the tool to work first then once that is the case you'll be abl to use Copy As Python Snippet from the Geoprocessing | Results window to get the Python code right. Commented Apr 18, 2012 at 22:38
  • I notice in the online help it says: "If you want to delete all features from an ArcSDE feature class, use this tool against the ArcSDE feature class (not a layer) without a selection in order to perform a database truncate rather than a row by row deletion of features to delete all the features. The database truncate operation is much faster when deleting all the features in a feature class." Have you tried using both the layer and the feature class? Also, have you tried deleting a feature class that is not in a feature dataset to see whether that works? Commented Apr 18, 2012 at 22:38

2 Answers 2

1

If you have delete rights, (and that isthe first thing you should check) and still the script does not run, then the problem is in the way that you are giving the path of the featureclass.

"Dataset Database Connections\Connection to sde.sde\User.MyFeatureDataset\User.MyFeatureClass" is a path that ArcCatlog & ArcMap undertsand, but not a standalone script.

What you need to do, is to give the complete path, including the location of the SDE connection. The SDE connection is usually in C:\Users\\AppData\Roaming\ESRI\Desktop10.0\ArcCatlog

You need to give the path of the featureclass as: "C:\Users\<User>\AppData\Roaming\ESRI\Desktop10.0\ArcCatlog\Connection to sde.sde\User.MyFeatureDataset\User.MyFeatureClass"

I have found that this path works when running stand alone scripts.

This question might explain the issue further: Define Workspace for SDE Connection in Python

answered Apr 19, 2012 at 3:41
1
  • 3
    shrug I've found the "Database Connections" shortcut to always work even in standalone Python scripts. Commented Apr 19, 2012 at 6:32
1

Came across this recently. This has solved the issue of deleting all of the features in a .sde connection. If you only want to clear specific features, you can use .remove() on the featureClasses list, or create your own list.

arcpy.env.workspace = r'path to sde connection of the sde database'
featureClasses = arcpy.ListFeatureClasses()
for fc in featureClasses:
 try:
 arcpy.DeleteFeatures_management(fc)
 except Exception as e:
 print e
answered Apr 10, 2015 at 18:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.