Select to view content in your preferred language

Generate Compact Unique IDs from GlobalID in ArcGIS Pro

376
1
01-08-2025 08:26 AM
Status: Closed
lal-sabbagh
Occasional Contributor

Problem

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.


Solution

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.


Features

  • Compact IDs: 4-character unique IDs derived from GlobalID.
  • Customizable: Adjust prefix (GID) or length as needed.
  • Universal: Works on file and enterprise geodatabases with edit session support.
  • Plug-and-Play: Easy integration into ArcGIS Pro workflows or custom toolboxes.

 

 

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)

 

1 Comment
HannesZiegler
Status changed to: Closed

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!