操作方法

操作方法:在 ArcMap 中使用 Python ListFields() 计算要素类中的字段总数

Last Published: July 20, 2023

摘要

In ArcGIS Desktop, the Get Count geoprocessing tool is used to calculate the total number of rows in an attribute table. However, this tool does not calculate the total number of columns, which represent the total number of fields in a feature class.

Calculating the total number of fields is useful when there are a number of attributes in a feature class. The total can be derived using the Python ListFields() function.

Table showing a number of attributes

过程

The workflow below describes how to calculate the total number of fields in a feature class using the Python ListFields() function.

  1. In ArcMap, click the Geoprocessing tab, and select Python to open the Python command window.
ArcMap Geoprocessing tab and window
  1. In the Python window, enter the Python ListFields() function.
print len(arcpy.ListFields(r"location of your feature class or shapefile","*")) 
Note: 
For more information on the function, refer to ArcMap: ListFields.

In this example, the following expression is used to count the fields in the Counties feature class:

print len(arcpy.ListFields(r"C:\Users\*****\Desktop\Data2\State.gdb\Counties","*"))
Fields in the Counties feature class
  1. Place the cursor at the end of the expression and press Enter. The image below shows the total number of fields for the Counties feature class is 5.
Total number of fields is 5

文章 ID: 000022586

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项