HOW TO
In ArcGIS Pro, some data may contain sequential numbers for maintaining data integrity, ensuring data quality, and supporting spatial analysis. In some cases, there are missing sequence numbers in the data, which can cause errors potentially leading to inconsistencies or inaccuracies in analysis, as shown in the image below.
This article describes the workflow to find the missing sequence number of a field in ArcGIS Pro using ArcPy.
Note: This workflow requires a full script to run in the ArcGIS Pro Python window. All the indents must be retained as portrayed in the code block.
import arcpy def find_missing_sequence(fc, field_name): sequence_numbers = []
with arcpy.da.SearchCursor(fc, [field_name]) as cursor: for row in cursor: # Convert the field value to an integer (assuming it's a float) sequence_numbers.append(int(row[0]))
min_seq = min(sequence_numbers) max_seq = max(sequence_numbers)
expected_sequence = list(range(min_seq, max_seq + 1))
missing_sequence = [num for num in expected_sequence if num not in sequence_numbers] return missing_sequence
if __name__ == "__main__": fc = "<featureClassName>" field_name = "<fieldName>"
missing_sequence = find_missing_sequence(fc, field_name) if missing_sequence: print("Missing sequence number(s):", missing_sequence) else: print("No missing sequence numbers found.")
The code block below demonstrates the full working script.
import arcpy def find_missing_sequence(fc, field_name): sequence_numbers = [] with arcpy.da.SearchCursor(fc, [field_name]) as cursor: for row in cursor: sequence_numbers.append(int(row[0])) min_seq = min(sequence_numbers) max_seq = max(sequence_numbers) expected_sequence = list(range(min_seq, max_seq + 1)) missing_sequence = [num for num in expected_sequence if num not in sequence_numbers] return missing_sequence if __name__ == "__main__": fc = "Point1" field_name = "Sequence" missing_sequence = find_missing_sequence(fc, field_name) if missing_sequence: print("Missing sequence number(s):", missing_sequence) else: print("No missing sequence numbers found.")
The image below shows the missing sequence number in the field using ArcPy.
Get help from ArcGIS experts
Download the Esri Support App