删除行 (Data Management)

许可等级:BasicStandardAdvanced

摘要

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

如果输入行来自要素类或表,则会删除所有行。如果输入行来自没有选定内容的图层或表视图,则会删除所有行。

用法

语法

DeleteRows_management (in_rows)
参数说明数据类型
in_rows

各行将被删除的要素类、图层、表或表视图。

Table View

代码实例

删除行 (DeleteRows) 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 DeleteRows 功能。

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.CopyRows_management("accident.dbf", "C:/output/accident2.dbf")
arcpy.DeleteRows_management("C:/output/accident2.dbf")
删除行 (DeleteRows) 示例 2(独立脚本)

以下独立脚本演示了如何使用 DeleteRows 功能基于表达式删除行。

# Name: DeleteRows_Example2.py
# Description: Delete rows from a table based on an expression
 
# Import system modules
import arcpy
from arcpy import env

try: 
    # Set environment settings
    env.workspace = "C:/data"
 
    # Set local variables
    inTable = "accident.dbf"
    outTable = "C:/output/new_accident.dbf"
    tempTableView = "accidentTableView"
    expression = arcpy.AddFieldDelimiters(tempTableView, "Measure") + " = 0"
 
    # Execute CopyRows to make a new copy of the table
    arcpy.CopyRows_management(inTable, outTable)
 
    # Execute MakeTableView
    arcpy.MakeTableView_management(outTable, tempTableView)
 
    # Execute SelectLayerByAttribute to determine which rows to delete
    arcpy.SelectLayerByAttribute_management(tempTableView, "NEW_SELECTION", expression)
 
    # Execute GetCount and if some features have been selected, then execute
    #  DeleteRows to remove the selected rows.
    if int(arcpy.GetCount_management(tempTableView).getOutput(0)) > 0:
        arcpy.DeleteRows_management(tempTableView)
         
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