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.

Is there a way to delete a feature data set and all of its feature classes programmatically either by using custom code or pre-existing command line tools?

There is a tool provided by SDE called sdetable.exe but i'm not sure if this will do the trick.

My feature data sets are setup in ArcSDE via scripts which call a custom executable that imports XML workspaces. I'd like a way to delete the feature data sets that the XML workspaces import because when I re-run the scripts I get things like this:

Underlying DBMS error [ORA-00972: identifier is too long

(VITD.Surface_Drainage_Channel_Area_1)]

The '_1' is appended because there is already a feature class named Surface_Drainage_Channel_Area. So I'd like to have my scripts first drop the VITD feature data set and all of its feature classes before importing my XML workspace XML document that creates it.

share|improve this question
    
You could certainly call your python script written in ArcPy or exported from ArcToolbox. –  Place - Zilla Mar 30 '11 at 14:21
add comment

3 Answers

sdetable (like all SDE command line tools) does not recognize/understand the Geodatabse. Because a feature dataset is a geodatabase object, you cannot use sdetable to delete it.

You'll need to stick with an ArcObjects based client to do a clean delete. The easiest way would be to use the delete geoprocessing tool.

share|improve this answer
add comment
up vote 1 down vote accepted

Thanks for pointing me in the right direction. Here is the ArcPy script I wrote that worked for me:

#-------------------------------------------------------------------------------
# Name:        RemoveSdeObjects.py
# Purpose:     Removes all feature datasets, classes and tables for a given user
#              
# Author:      Andy Arismendi
# Created:     23/06/2011
#-------------------------------------------------------------------------------
#!/usr/bin/env python

from optparse import OptionParser
import sys
import os.path
import arcpy
from arcpy import env

def RemoveAllSdeObjects (workspace, user):
    import arcpy
    from arcpy import env

    env.overwriteOutput = True
    env.workspace = workspace

    try:
        datasetList = arcpy.ListDatasets((user + ".*"), "All")

        # Check if the connection failed.
        # Look for message: 'WARNING 000565: Could not connect to server.'
        connMsg = arcpy.GetMessage(2)
        if ('WARNING 000565:' in connMsg):
            raise Exception(connMsg)

        for dataset in datasetList:
            arcpy.Delete_management(dataset)

        featureClassList = arcpy.ListFeatureClasses((user + ".*"), "All")
        for featureClass in featureClassList:
            arcpy.Delete_management(featureClass)

        tableList = arcpy.ListTables((user + ".*"), "All")
        for table in tableList:
            arcpy.Delete_management(table)
    except:
        raise Exception(arcpy.GetMessages() + "\n")
    finally:
        env.workspace = ""

def main():
    # Process parameters.
    try:
        usage = "usage: %prog [options]"
        parser = OptionParser(usage=usage)

        parser.add_option(
            "-s", action="store", type="string", dest="server",
                help="The SDE server name or IP address.")

        parser.add_option(
            "-i", action="store", type="int", dest="port",
                help="The SDE instance port number.")

        parser.add_option(
            "-u", action="store", type="string", dest="username",
                help="The schema owner username.")

        parser.add_option(
            "-p", action="store", type="string", dest="password",
                help="The schema owner password.")

        (options, args) = parser.parse_args()

        # All parameters are required.
        if options.server == None:
            parser.error("Missing required parameter: '-s SDE_SERVER'.")
        if options.port == None:
            parser.error("Missing required parameter: '-i SDE_PORT'.")
        if options.username == None:
            parser.error("Missing required parameter: '-u SCHEMA_OWNER_USERNAME'.")
        if options.password == None:
            parser.error("Missing required parameter: '-p SCHEMA_OWNER_PASSWORD'.")
    except:
        parser.print_help()
        sys.exit(1)


    try:
        sdeConnectionFileDir = os.environ.get("TEMP")
        if sdeConnectionFileDir == None:
            raise Exception("Required environment variable is not defined: 'TEMP'.")

        databaseName = ""
        fileName = options.username + " to " + options.server + ".sde"

        # Delete any pre-existing SDE connection file.
        fullPath = sdeConnectionFileDir + '\\' + fileName
        if os.path.exists(fullPath):
            os.remove(fullPath)

        # Create temporary SDE connection file.
        try:
            arcpy.CreateArcSDEConnectionFile_management (
                sdeConnectionFileDir, fileName,
                options.server, options.port, options.server,
                "DATABASE_AUTH", options.username, options.password,
                "SAVE_USERNAME",
                "SDE.DEFAULT", "SAVE_VERSION"
                )
        except:
            raise Exception(arcpy.GetMessages() + "\n")

        # Remove all SDE objects owned by this user.
        RemoveAllSdeObjects(fullPath, options.username)

        # Remove temporary SDE connection file.
        os.remove(fullPath)
    except Exception as e:
        print "Failed to remove SDE objects.", e
        sys.exit(1)

if __name__ == '__main__':
    main()
share|improve this answer
add comment

You will have to delete the featureclasses first, then the container featuredataset. The featuredataset will have to be empty before you can delete it. You might want to look at the IDataset.Delete method

share|improve this answer
    
Why does the feature dataset have to be empty? Is that so that you cover the case where a feature dataset contains a topology or geometric network which would prevent the feature dataset from being deleted? –  Derek Swingley Mar 16 '11 at 20:55
    
@Swingley - I guess it's just like deleting a FD in ArcCatalog - has to be empty of FCs first. –  Chad Cooper Mar 16 '11 at 21:08
    
@Chad- If you only have simple features in your feature dataset, you can delete the feature dataset without deleting the feature classes first. –  Derek Swingley Mar 16 '11 at 21:13
    
@Swingley-Really? Well, I stand corrected! I'll have to try that. –  Chad Cooper Mar 16 '11 at 21:26
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.