Raster Fields Not Supported Using Cursors

1465
7
03-25-2019 01:17 PM
JaredPilbeam2
MVP Regular Contributor

How do I update a Raster Field using a cursor? I'm attempting to write a script that uses a cursor to update this field with rasters from a directory. It's a stand-alone script using arcpy for ArcGIS Pro 2.3.1.

arcpy.da.InsertCursor, arcpy.da.SearchCursor and arcpy.da.UpdateCursor state that as a field_name, "Raster fields are not supported."

Tags (2)
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

So creating a separate table (using an insertcursor) for joining isn't a possibility?

Join Field—Data Management toolbox | ArcGIS Desktop 

This join is permanent if memory serves

0 Kudos
JaredPilbeam2
MVP Regular Contributor

So creating a separate table (using an insertcursor) for joining isn't a possibility?

How to use an insertcursor on a Raster Field is pretty much my question. There's a Raster Field in a FC that I want populated with rasters. But, as I was reading how to access that type of field with a cursor it says it's not possible:


DanPatterson_Retired
MVP Emeritus

I was referring more to hyperlinking to the data or similar.

Adding raster datasets as attributes in a feature class—ArcGIS Pro | ArcGIS Desktop

is the remaining option, which would probably only be useful for a few

JaredPilbeam2
MVP Regular Contributor

Dan,

Adding raster datasets as attributes is exactly what I need. But is there a way to automate this? I'm dealing with 1000s of rasters. I started out on this page and because there was no mention of Arcpy I moved on to looking into cursors.

0 Kudos
KevinTientcheu3
New Contributor II

Hello Jared, 

Maybe the following thread can get you closer to what you are looking for: https://community.esri.com/thread/92354 

I hope it helps!

JaredPilbeam2
MVP Regular Contributor

For what it's worth, it looks like I can convert the rasters to a FGDB

arcpy.env.workspace = r'\pathTo\jpgs'

#Convert Multiple Raster Dataset to FGDB
arcpy.RasterToGeodatabase_conversion("0100030.jpg;0100040.jpg", r"\pathTo\Data.gdb")‍‍‍‍

Of course, this is just a sample. I'll have to set the script up to iterate through the directory and convert thousands of jpgs to the FGDB. But, after I do that I'm still stuck wondering how to get the raster into the Raster Field via Python. 

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Thanks to GeoNet, here's the work around I eventually came up with seeing that using Python to update a raster field isn't supported.

In the end I didn't use a raster field at all. I had a text field with a unique ID that matched the file name of JPGs in a directory. I used a script that updated another text field named 'Photo' with the full name of the JPG. Then I used arcpy.EnableAttachments_management(), which created a related table that can store rasters. Finally, I used arcpy.AddAttachments_management(), which populated the related table. Working with attachments was also helpful. 

'''the purpose of this script is to update the 'Photo' field in the fc
with the file path of the same name.
'''
import arcpy, os

ws = r'path\to\Projects\DOT_SignInventory\pics'
jpgs = {} # empty dictionary

for dirName, subdirList, fileList in os.walk(ws):
    for fname in fileList:
        jpgs[fname[:-4]] = os.path.join(dirName,fname)
        for jpg in jpgs:
            print(jpg)

fc = r'path\to\Projects\DOT_SignInventory\Data2.gdb\WCDOT_Signs'
fields = ['OID@', 'Post_Number', 'Photo']

with arcpy.da.UpdateCursor(fc, fields) as cursor:
    for row in cursor:
        try:
            row[2] = jpgs[row[1]]
            cursor.updateRow(row)
        except KeyError:
            print("No photo for: {}".format(row[1]))

del cursor‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos