操作方法

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

Last Published: July 21, 2023

摘要

In ArcGIS Pro, 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 represents the total number of fields in a feature class.

Providing a method to calculate this is helpful when there is a large number of attributes in a feature class. This is achieved using the Python ListFields() function.

An attribute table of a feature class.

过程

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

  1. In ArcGIS Pro, on the Analysis tab, click the down arrow next to Python, and select Python window.
the Analysis tab and the drop-down menu of the Python button. Python Notebook and Python window are listed in the drop-down menu.
  1. In the Python window, in the prompt section, enter the Python ListFields() function as shown below. Refer to ArcGIS Pro: ListFields for more information.
import arcpy
fields = arcpy.ListFields('Feature Class Name')
print(len(fields))
Note:
Do not remove the single quotation marks enclosing the feature class name.

In this example, the feature class is Asia.

The Python window prompt section.
  1. Place the cursor at the end of the expression and press Enter twice on the keyboard. The image below shows the total number of fields for the Asia feature class is 8.
The Python window with the result after executing the ListField funtion.

文章 ID: 000023096

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

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

下载 Esri 支持应用程序

相关信息

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

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项