操作方法

操作方法:在字段计算器中使用 Python 在 ArcMap 的字段中创建序号

Last Published: April 19, 2024

摘要

Instructions provided describe how to create sequential numbers in a field in ArcMap using Python in the Field Calculator.

过程

Note:
The code in this article generates sequential numbers for unsorted data based on the OID or FID order. If the data is sorted on a field, the generated numbers are not sequential.
  1. Create a new short integer field. Refer to ArcMap: Adding fields for instructions.
  2. Right-click the new field and select Field Calculator.
  3. Set the Parser to Python.
  4. Check the check box for Show Codeblock.
  5. Paste the following into the Pre-Logic Script Code:
rec=0 
def autoIncrement(): 
 global rec 
 pStart = 1  
 pInterval = 1 
 if (rec == 0):  
  rec = pStart  
 else:  
  rec += pInterval  
 return rec
  1. Paste the following code in the smaller box below the Pre-Logic Script Code:
autoIncrement()
  1. Click OK. The following image is an example of a field with sequential numbers populated using the Python code:
An attribute table with a field with sequential numbers.

文章 ID:000011137

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

相关信息

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