GlobalID fields in ArcGIS are robust but too long for compact reports, fieldwork, or external systems requiring shorter, user-friendly unique IDs. GIS professionals often need a scalable solution to derive such IDs without compromising uniqueness.
This Python script hashes the GlobalID field to generate a 4-character unique ID prefixed with "GID" (e.g., GID1234). It automates the creation of a new field for example (GIS_ID) to store these IDs, ensuring efficient and compact ID generation directly in ArcGIS Pro.
import arcpy
import hashlib
workspace = r"C:\Path\To\Your\Geodatabase.gdb"
input_fc = "YourFeatureClass"
global_id_field, gis_id_field = "GlobalID", "GIS_ID"
if gis_id_field not in [f.name for f in arcpy.ListFields(input_fc)]:
arcpy.AddField_management(input_fc, gis_id_field, "TEXT", field_length=8)
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
try:
with arcpy.da.UpdateCursor(input_fc, [global_id_field, gis_id_field]) as cursor:
for row in cursor:
if row[0]:
row[1] = f"GID{int(hashlib.md5(row[0].encode()).hexdigest(), 16) % 10000:04d}"
cursor.updateRow(row)
edit.stopEditing(True)
except:
edit.stopEditing(False)
Thank you for sharing your idea with us, it looks like it can be very useful for condensing global IDs into a shorter representation. Keep in mind that this can lead to collisions, please use with caution. It sounds like this is something you are sharing with the community rather than an idea for the product. If you are just wanting to share your work with others in case it would help fulfill their needs too, this is better suited for the Esri Community forum rather than here. Please also see the ArcGIS Ideas Submission Guidelines.
We appreciate your willingness to share your knowledge, it can be extremely helpful for us and others!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.