Delete Features (Data Management)

Summary

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

The deletion of all features or a subset of features depends on the following:

  • If the input is a feature class, all features will be deleted.
  • If the input is a layer with no selection, all features will be deleted.
  • If the input is a layer with a selection, only the selected features will be deleted.

Usage

  • This tool accepts layers with selections as input and will delete only those features that are selected. To delete specific features from a feature class, convert the feature class to a layer using the Make Feature Layer tool or by adding it to the display. A selection can then be applied using the Select Layer By Attribute or Select Layer By Location tool, by querying a map layer, or by selecting features interactively using selection tools from the Selection group on the Map tab.

  • Note:

    Deleting all features from a feature class with a large number of features can take time. If the intent is to delete all the features, consider using the Truncate Table tool instead. See the Truncate Table documentation for important cautionary statements on its use.

  • This tool deletes both the geometry and attributes of the Input Features value.

  • The Extent environment is honored by this tool. Only the features that are within or intersect the output extent environment will be deleted. If the input layer has a selection, only the selected features that are within or intersect the output extent will be deleted.

Parameters

LabelExplanationData Type
Input Features

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

Feature Layer

Derived Output

LabelExplanationData Type
Output Feature Class

The updated feature class.

Feature Layer

arcpy.management.DeleteFeatures(in_features)
NameExplanationData Type
in_features

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

Feature Layer

Derived Output

NameExplanationData Type
out_feature_class

The updated feature class.

Feature Layer

Code sample

DeleteFeatures example 1 (Python window)

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

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

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

# 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'"
 

# Run CopyFeatures to make a new copy of the feature class
arcpy.management.CopyFeatures(inFeatures, outFeatures)
 
# Run MakeFeatureLayer
arcpy.management.MakeFeatureLayer(outFeatures, tempLayer)
 
# Run SelectLayerByAttribute to determine which features to delete
arcpy.management.SelectLayerByAttribute(tempLayer, "NEW_SELECTION", 
                                        expression)
 
# Run GetCount and if some features have been selected, 
#  run DeleteFeatures to remove the selected features.
if int(arcpy.management.GetCount(tempLayer)[0]) > 0:
    arcpy.management.DeleteFeatures(tempLayer)

Environments

Special cases

Extent

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

Related topics