ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

删除字段

  • 描述
  • 使用方法
  • 语法
  • 代码示例
  • 环境
  • 许可信息

描述

此工具可从表、要素类、要素图层或栅格数据集中删除一个或多个字段。

使用方法

  • 此工具适用于任何表;企业级、文件或个人地理数据库要素类;coverage;栅格数据集或 shapefile。

  • 不能从 ArcGIS 的非本地只读数据格式中删除字段,例如:VPF 和 CAD 数据集。

  • 删除字段参数的添加字段按钮仅可以在 ModelBuilder 中使用。在 ModelBuilder 中,如果先前的工具尚未运行或其派生数据不存在,则可能不会使用字段名称来填充删除字段参数。添加字段按钮可用于添加所需字段,以完成“删除字段”对话框并继续构建模型。

语法

arcpy.management.DeleteField(in_table, drop_field)
参数说明数据类型
in_table

包含要删除字段的表。将修改现有输入表。

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
drop_field
[drop_field,...]

要从输入表中删除的字段。必填字段不能删除。

Field

代码示例

DeleteField 示例(Python 窗口)

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

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.CopyFeatures_management("majorrds.shp", "C:/output/majorrds_copy.shp")
arcpy.DeleteField_management("C:/output/majorrds_copy.shp", 
                             ["STREET_NAM", "LABEL", "CLASS"])
DeleteField 示例 2(独立脚本)

以下独立脚本演示了如何使用 DeleteField 工具:

# Name: DeleteField_Example2.py
# Description: Delete several fields from a feature class
  
# Import system modules
import arcpy
 
# Set environment settings
arcpy.env.workspace = "C:/data"
 
# Set local variables
inFeatures = "accident.dbf"
outFeatureClass = "C:/output/new_accident.dbf"
dropFields = ["STREET_NAM", "LABEL", "CLASS"]
 
# Execute CopyFeatures to make a new copy of the feature class
#  Use CopyRows if you have a table
arcpy.CopyFeatures_management(inFeatures, outFeatureClass)
 
# Execute DeleteField
arcpy.DeleteField_management(outFeatureClass, dropFields)
DeleteField 示例 3(独立脚本)

使用 DeleteField 可从要素类或表中清除所有不需要的字段。

# Name: DeleteFields_clearfields.py
# Description: Delete unrequired fields from a feature class or table.
 
# Import system modules
import arcpy
 
try: 
    # Get user-supplied input and output arguments
    inTable = arcpy.GetParameterAsText(0)
    updatedTable = arcpy.GetParameterAsText(1)
 
    # Describe the input (need to test the dataset and data types)
    desc = arcpy.Describe(updatedTable)
 
    # Make a copy of the input (so we can mantain the original as is)
    if desc.datasetType == "FeatureClass":
        arcpy.CopyFeatures_management(inTable, updatedTable)
    else:
        arcpy.CopyRows_management(inTable, updatedTable)
 
    # Use ListFields to get a list of field objects
    fieldObjList = arcpy.ListFields(updatedTable)
 
    # Create an empty list that will be populated with field names        
    fieldNameList = []
 
    # For each field in the object list, add the field name to the
    #  name list.  If the field is required, exclude it, to prevent errors
    for field in fieldObjList:
        if not field.required:
            fieldNameList.append(field.name)
 
    # dBASE tables require a field other than an OID and Shape.  If this is
    #  the case, retain an extra field (the first one in the original list)
    if desc.dataType in ["ShapeFile", "DbaseTable"]:
        fieldNameList = fieldNameList[1:]
 
    # Execute DeleteField to delete all fields in the field list. 
    arcpy.DeleteField_management(updatedTable, fieldNameList)
          
except Exception as err:
    print(err.args[0])

环境

  • 当前工作空间

许可信息

  • Basic: 是
  • Standard: 是
  • Advanced: 是

相关主题

  • 字段工具集概述

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明