Delete Features (Data Management)

License Level:BasicStandardAdvanced

Summary

Deletes all or the selected subset of features from the input.

If the input features are from a feature class or table, all rows will be deleted. If the input features are from a layer with no selection, all features will be deleted.

Usage

Syntax

DeleteFeatures_management (in_features)
ParameterExplanationData Type
in_features

The feature class, shapefile, or layer containing features to be deleted.

Feature Layer

Code Sample

DeleteFeatures example 1 (Python window)

The following Python window script demonstrates how to use the DeleteFeatures tool in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.CopyFeatures_management("majorrds.shp", "C:/output/output.gdb/majorrds2")
arcpy.DeleteFeatures_management("C:/output/output.gdb/majorrds2")
DeleteFeatures example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the DeleteFeatures tool to delete features based on an expression.

# Name: DeleteFeatures_Example2.py
# Description: Delete features from a feature class based on an expression
 
# Import system modules
import arcpy
 
# Set environment settings
arcpy.env.workspace = "C:/data/airport.gdb"
 
# Set local variables
inFeatures = "parcels"
outFeatures = "C:/output/output.gdb/new_parcels"
tempLayer = "parcelsLayer"
expression = arcpy.AddFieldDelimiters(tempLayer, "PARCEL_ID") + " = 'Cemetery'"
 
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 int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
        arcpy.DeleteFeatures_management(tempLayer)
         
except Exception:
    e = sys.exc_info()[1]
    arcpy.AddError(e.args[0])

Environments

Extent

Only those features that are within or intersect the extent will be deleted.

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015