<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>idea Generate Compact Unique IDs from GlobalID in ArcGIS Pro in Python Ideas</title>
    <link>https://community.esri.com/t5/python-ideas/generate-compact-unique-ids-from-globalid-in/idi-p/1573569</link>
    <description>&lt;H3&gt;Problem&lt;/H3&gt;&lt;P&gt;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.&lt;/P&gt;&lt;HR /&gt;&lt;H3&gt;Solution&lt;/H3&gt;&lt;P&gt;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.&lt;/P&gt;&lt;HR /&gt;&lt;H3&gt;Features&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Compact IDs&lt;/STRONG&gt;: 4-character unique IDs derived from GlobalID.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Customizable&lt;/STRONG&gt;: Adjust prefix (GID) or length as needed.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Universal&lt;/STRONG&gt;: Works on file and enterprise geodatabases with edit session support.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Plug-and-Play&lt;/STRONG&gt;: Easy integration into ArcGIS Pro workflows or custom toolboxes.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2025 16:26:23 GMT</pubDate>
    <dc:creator>lal-sabbagh</dc:creator>
    <dc:date>2025-01-08T16:26:23Z</dc:date>
    <item>
      <title>Generate Compact Unique IDs from GlobalID in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-ideas/generate-compact-unique-ids-from-globalid-in/idi-p/1573569</link>
      <description>&lt;H3&gt;Problem&lt;/H3&gt;&lt;P&gt;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.&lt;/P&gt;&lt;HR /&gt;&lt;H3&gt;Solution&lt;/H3&gt;&lt;P&gt;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.&lt;/P&gt;&lt;HR /&gt;&lt;H3&gt;Features&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Compact IDs&lt;/STRONG&gt;: 4-character unique IDs derived from GlobalID.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Customizable&lt;/STRONG&gt;: Adjust prefix (GID) or length as needed.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Universal&lt;/STRONG&gt;: Works on file and enterprise geodatabases with edit session support.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Plug-and-Play&lt;/STRONG&gt;: Easy integration into ArcGIS Pro workflows or custom toolboxes.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 16:26:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/generate-compact-unique-ids-from-globalid-in/idi-p/1573569</guid>
      <dc:creator>lal-sabbagh</dc:creator>
      <dc:date>2025-01-08T16:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Compact Unique IDs from GlobalID in ArcGIS Pro - Status changed to: Closed</title>
      <link>https://community.esri.com/t5/python-ideas/generate-compact-unique-ids-from-globalid-in/idc-p/1579311#M428</link>
      <description>&lt;P&gt;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 &lt;A href="https://community.esri.com/t5/tag/arcpy/tg-p/board-id/arcgis-pro-questions" target="_self"&gt;Esri Community&lt;/A&gt; forum rather than here.&amp;nbsp;Please also see the &lt;A href="https://community.esri.com/t5/community-help-documents/arcgis-ideas-submission-guidelines-and-statuses/ta-p/904874" target="_self"&gt;ArcGIS Ideas Submission Guidelines&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;We appreciate your willingness to share your knowledge, it can be extremely helpful for us and others!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 22:43:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/generate-compact-unique-ids-from-globalid-in/idc-p/1579311#M428</guid>
      <dc:creator>HannesZiegler</dc:creator>
      <dc:date>2025-01-27T22:43:04Z</dc:date>
    </item>
  </channel>
</rss>

