删除要素 (数据管理)

摘要

从输入要素类或图层中删除要素。如果输入是具有选定内容的图层,则仅会删除所选要素。如果输入是地理数据库要素类或 shapefile,则会删除所有要素。

用法

语法

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

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

Feature Layer

代码示例

DeleteFeatures 示例(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
# Author: ESRI
 
# 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, 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

环境

范围

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

相关主题

许可信息

ArcView: 是
ArcEditor: 是
ArcInfo: 是

7/10/2012