删除要素 (数据管理)
摘要
从输入要素类或图层中删除要素。如果输入是具有选定内容的图层,则仅会删除所选要素。如果输入是地理数据库要素类或 shapefile,则会删除所有要素。
用法
-
该工具接受将包含选择内容的图层作为输入,且仅会删除所选要素。要从要素类中删除特定要素,请使用创建要素图层将要素类转换为图层,或通过将要素类添加到 ArcMap 显示中来执行此操作。然后可使用按属性选择图层或按位置选择图层工具进行选择,或者使用 ArcMap 中的选择箭头通过查询地图图层或选择要素进行选择。
-
该工具将同时删除输入要素的几何和属性。
-
在 ArcMap 中操作时,如果在编辑会话中使用此工具,则允许通过撤消/恢复来撤消“删除要素”操作。
-
如果要删除要素类中的所有要素,请对不包含选择内容的要素类或图层使用此工具。
-
如果要删除 ArcSDE 要素类中的所有要素,请针对不包含选择内容的 ArcSDE 要素类(不是图层)使用此工具,即可执行数据库截断,而不是通过逐行删除要素来删除所有要素。当删除要素类中的所有要素时,数据库截断操作的速度会更快。
语法
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