<?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>topic Re: Move Raster from field to attachment in Geodatabase Questions</title>
    <link>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1638028#M9679</link>
    <description>&lt;P&gt;Thanks for the code.&amp;nbsp; It did not all work, but it got me on the right track and I was able to complete the task.&amp;nbsp; Here is the code as I modified it:&lt;/P&gt;&lt;DIV&gt;import arcpy&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;with arcpy.da.SearchCursor("GEO.Section_Control_Points", ["Picture", "GLOBALID@"]) as cursor:&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;for row in cursor:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;raster_object = row[0]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;global_id = row[1]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;output_image = arcpy.os.path.join(r"C:\\tempoutput\\", f"raster_{global_id}.tif")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if raster_object is not None:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;raster_object.save(output_image)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy.AddMessage(f"Exported raster from GLOBALID {global_id} to {output_image}")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy.AddMessage(f"No raster found for GLOBALID {global_id}")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The code allowed me to create a folder with all the attachments, but I could not get the code to add the rasters as attachments to work, but I was able to manually use the geoprocessing tool "Generate Attachment Table" like this:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Syvertson_0-1753973981676.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137597i0783ED77B79FB3CD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Syvertson_0-1753973981676.png" alt="Syvertson_0-1753973981676.png" /&gt;&lt;/span&gt;&lt;P&gt;and then the "Add Attachments" tool, like this:&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Syvertson_1-1753974041677.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137598iEB7A760BC1FEB6A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Syvertson_1-1753974041677.png" alt="Syvertson_1-1753974041677.png" /&gt;&lt;/span&gt;&lt;P&gt;It all worked!&amp;nbsp; Thanks.&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 31 Jul 2025 15:01:04 GMT</pubDate>
    <dc:creator>Syvertson</dc:creator>
    <dc:date>2025-07-31T15:01:04Z</dc:date>
    <item>
      <title>Move Raster from field to attachment</title>
      <link>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1636477#M9669</link>
      <description>&lt;P&gt;I have a geodatabase feauture class that we have been using for years.&amp;nbsp; We used to collect an image into a raster field for each feature in the Enterprise Geodatabase (SQL Server).&amp;nbsp; With our new field maps collecton process I cannot figure out how to collect into the raster field, so we have enabled attachments.&amp;nbsp; I would like to now move any existing pictures from the raster field into an attachment.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-07-25 113121.png" style="width: 545px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137252iD2AD89B07F14E8B9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-07-25 113121.png" alt="Screenshot 2025-07-25 113121.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need guidance/advice!&lt;/P&gt;&lt;P&gt;Matt Syvertson&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 16:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1636477#M9669</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2025-07-25T16:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Move Raster from field to attachment</title>
      <link>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1637173#M9670</link>
      <description>&lt;P&gt;This should be easy to do with ArcPy. Save the raster out and add it back to the related attachments table.&lt;/P&gt;&lt;P&gt;My python is rusty so I asked CoPilot.&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;Script Explanation:&lt;BR /&gt;Extract the raster data from the raster field.&lt;BR /&gt;Save the raster data as an image file.&lt;BR /&gt;Add the saved image as an attachment to the corresponding feature.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# Input feature class
feature_class = r"path\to\your\feature_class"
raster_field = "RasterFieldName"  # Replace with your raster field name
attachment_table = r"path\to\your\attachment_table"  # Attachment table path
output_folder = r"path\to\output\folder"  # Temporary folder to save images

# Ensure output folder exists
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# Add attachments if not already enabled
if not arcpy.Describe(feature_class).hasAttachments:
    arcpy.EnableAttachments_management(feature_class)

# Iterate through features
with arcpy.da.SearchCursor(feature_class, ["OID@", raster_field]) as cursor:
    for oid, raster in cursor:
        if raster:
            # Save raster to a temporary file
            output_image = os.path.join(output_folder, f"feature_{oid}.jpg")
            raster.save(output_image)

            # Add the image as an attachment
            arcpy.AddAttachments_management(
                feature_class,
                "OBJECTID",
                attachment_table,
                "REL_OBJECTID",
                "ATTACHMENTID",
                output_image
            )

            # Optionally, delete the raster field value (if needed)
            with arcpy.da.UpdateCursor(feature_class, [raster_field], f"OBJECTID = {oid}") as update_cursor:
                for row in update_cursor:
                    row[0] = None
                    update_cursor.updateRow(row)

print("Images moved to attachments successfully!")&lt;/LI-CODE&gt;&lt;P&gt;Notes:&lt;BR /&gt;Replace placeholders like path\to\your\feature_class, RasterFieldName, and path\to\output\folder with your actual paths and field names.&lt;BR /&gt;Ensure the feature class has attachments enabled. If not, the script will enable it.&lt;BR /&gt;The script saves raster images temporarily in the specified folder. You can clean up this folder after execution.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 01:44:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1637173#M9670</guid>
      <dc:creator>sjones_esriau</dc:creator>
      <dc:date>2025-07-29T01:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Move Raster from field to attachment</title>
      <link>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1637740#M9678</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; I will try this and report back.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jul 2025 18:02:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1637740#M9678</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2025-07-30T18:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Move Raster from field to attachment</title>
      <link>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1638028#M9679</link>
      <description>&lt;P&gt;Thanks for the code.&amp;nbsp; It did not all work, but it got me on the right track and I was able to complete the task.&amp;nbsp; Here is the code as I modified it:&lt;/P&gt;&lt;DIV&gt;import arcpy&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;with arcpy.da.SearchCursor("GEO.Section_Control_Points", ["Picture", "GLOBALID@"]) as cursor:&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;for row in cursor:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;raster_object = row[0]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;global_id = row[1]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;output_image = arcpy.os.path.join(r"C:\\tempoutput\\", f"raster_{global_id}.tif")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if raster_object is not None:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;raster_object.save(output_image)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy.AddMessage(f"Exported raster from GLOBALID {global_id} to {output_image}")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy.AddMessage(f"No raster found for GLOBALID {global_id}")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The code allowed me to create a folder with all the attachments, but I could not get the code to add the rasters as attachments to work, but I was able to manually use the geoprocessing tool "Generate Attachment Table" like this:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Syvertson_0-1753973981676.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137597i0783ED77B79FB3CD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Syvertson_0-1753973981676.png" alt="Syvertson_0-1753973981676.png" /&gt;&lt;/span&gt;&lt;P&gt;and then the "Add Attachments" tool, like this:&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Syvertson_1-1753974041677.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/137598iEB7A760BC1FEB6A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Syvertson_1-1753974041677.png" alt="Syvertson_1-1753974041677.png" /&gt;&lt;/span&gt;&lt;P&gt;It all worked!&amp;nbsp; Thanks.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 31 Jul 2025 15:01:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/move-raster-from-field-to-attachment/m-p/1638028#M9679</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2025-07-31T15:01:04Z</dc:date>
    </item>
  </channel>
</rss>

