CÓMO

Calcular el número total de campos en una clase de entidad mediante el uso de ListFields() de Python en ArcMap

Last Published: July 20, 2023

Resumen

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

Procedimiento

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. de artículo: 000022586

Recibir notificaciones y encontrar soluciones a problemas nuevos o comunes

Obtenga respuestas resumidas y soluciones de vídeo de nuestro nuevo chatbot de IA.

Descargar la aplicación de soporte de Esri

Información relacionada

Descubrir más sobre este tema

Obtener ayuda de expertos en ArcGIS

Contactar con el soporte técnico

Descargar la aplicación de soporte de Esri

Ir a opciones de descarga