HOW TO
Sorting and creating a sequentially ordered ID field in an attribute table in ArcGIS Pro is an efficient way to organize data. The largest and smallest values, or perhaps the most and least significant features in a layer become easily recognizable.
The following steps describe how to sort and create a sequentially ordered ID field in an attribute table in ArcGIS Pro using three different options: the sort ascending or sort descending function, the calculate field function, or a Python script.
Using the Sort Ascending or Sort Descending function
Using the Calculate Field function
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.
Using a Python script through the Python window
The following steps demonstrate how to create sorted sequential numbers using the autoIncrement() ArcPy function:
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
This is the full script used in this article.
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
Artikel-ID:000018847
Unterstützung durch ArcGIS-Experten anfordern
Esri Support App herunterladen