We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,520 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Please Help: ArcPy- Delete Feature Class

I am very new to Python and scripting and am trying to write script to delete any point feature classes in my .gdb. I have found an example, but can't get it to run. Your help is greatly appreciated.

import arcpy

arcpy.env.workspace = r"E:\GIS_255\Week5\Harmon_Wk5_GIS255\KingCounty.gdb"

import string

try:

    fcList = arcpy.ListFeatureClasses("","point", "")
    
    for fc in fcList:
        Lst = arcpy.Describe(fc)
        
        if string.lower(Lst.shapeType) == "point":         
            print str(fc) + " is a " + Lst.shapeType + " feature class"
        
        else:
            print str(fc) + "The shapetype is unknown"

except:
    print "Script failed"

# Set local variables
inFeatures = "points" 
outFeatures = r"E:\GIS_255\Week5\Harmon_Wk5_GIS255\output.gdb\new_points"
tempLayer = "pointsLayer"
expression = arcpy.AddFieldDelimiters(pointsLayer, "Point_ID") + " = 'busstop'" + " = 'bridges'"
 
try:
    # Execute CopyFeatures to make a new copy of the feature class
    arcpy.CopyFeatures_management(inFeatures, outFeatures)
 
    # Execute MakeFeatureLayer
    arcpy.MakeFeatureLayer_management(outFeatures, tempLayer)
 
    # Execute SelectLayerByAttribute to determine which features to delete
    arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION", 
                                            expression)
 
    # Execute GetCount and if some features have been selected, then 
    #  execute DeleteFeatures to remove the selected features.
    if arcpy.GetCount_management(tempLayer) > 0:
        arcpy.DeleteFeatures_management(tempLayer)
         
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
1
Contributor
0
Replies
1
View
harmons4
Newbie Poster
3 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0856 seconds using 2.81MB