删除要素 (Data Management)

许可等级:BasicStandardAdvanced

摘要

从输入中删除所有要素或所选要素子集。

如果输入要素来自要素类或表,则将删除所有行。如果输入要素来自没有任何选择内容的图层,则将删除所有要素。

用法

语法

DeleteFeatures_management (in_features)
参数说明数据类型
in_features

包含要删除要素的要素类、shapefile 或图层。

Feature Layer

代码实例

删除要素 (DeleteFeatures) 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 DeleteFeatures 工具。

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.CopyFeatures_management("majorrds.shp", "C:/output/output.gdb/majorrds2")
arcpy.DeleteFeatures_management("C:/output/output.gdb/majorrds2")
删除要素 (DeleteFeatures) 示例 2(独立脚本)

以下独立脚本演示了如何使用 DeleteFeatures 工具基于表达式删除要素。

# Name: DeleteFeatures_Example2.py
# Description: Delete features from a feature class based on an expression
 
# Import system modules
import arcpy
from arcpy import env
 
# Set environment settings
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 as e:
    # If an error occurred, print line number and error message
    import traceback
    import sys
    tb = sys.exc_info()[2]
    print("Line {0}".format(tb.tb_lineno))
    print(e.message)

环境

范围

仅会删除位于范围内或与范围相交的要素。

相关主题

许可信息

ArcGIS for Desktop Basic: 是
ArcGIS for Desktop Standard: 是
ArcGIS for Desktop Advanced: 是
5/10/2014