操作方法
在 ArcGIS Pro 的属性表中排序和创建按顺序排列的 ID 字段是一种组织数据的有效方法。 图层中的最大值和最小值,或者最重要要素和最不重要要素都将变得易于识别。
以下步骤将介绍如何使用以下三个不同的选项在 ArcGIS Pro 的属性表中排序和创建按顺序排列的 ID 字段:升序排序或降序排序函数、计算字段函数和 Python 脚本。
使用升序排序或降序排序函数
使用“计算字段”函数
Note: This option only generates sequential numbers for unsorted data based on the OBJECTID order. If the data is sorted, the generated numbers are not sequential.
通过 Python 窗口使用 Python 脚本
以下步骤演示了如何使用 autoIncrement() ArcPy 函数创建序号:
import arcpy
sortFeat = r'[Geodatabase]\[Feature]' sortField = '[Base Field to sort]' idField = '[Field to populate sequential numbers]'
Note: To create the sequential numbers in a new field, create a new field and specify the new field name in the idField segment. Refer to ArcGIS Pro: Add Field for more information on creating a new field.
rec = 0
def autoIncrement(): global rec pStart = 1 pInterval = 1 if (rec == 0): rec = pStart else: rec += pInterval return rec
rows = arcpy.UpdateCursor(sortFeat, "", "", "", sortField + " A") for row in rows: row.setValue(idField, autoIncrement()) rows.updateRow(row) del row, rows
这是本文中使用的完整脚本。
import arcpy sortFeat = r'C:\Users\\Northridge.gdb\Stations' sortField = 'OBJECTID' idField = 'Station' rec=0 def autoIncrement(): global rec pStart = 1 pInterval = 1 if (rec == 0): rec = pStart else: rec += pInterval return rec rows = arcpy.UpdateCursor(sortFeat, "", "", "", sortField + " A") for row in rows: row.setValue(idField, autoIncrement()) rows.updateRow(row) del row, rows
文章 ID: 000018847
获取来自 ArcGIS 专家的帮助
下载 Esri 支持应用程序
You can also download the app to access the chatbot anytime! Download it now.