Working with RASTER type fields in ArcGIS 10.0 and Python 2.6.5

2321
2
06-10-2014 06:07 AM
GastonIzaguirre
New Contributor III
Hello all,

I have the following problem. I need to export a bunch of photos from a raster field in a feature class in SDE, naming them by some property of the feature class. I know to export them by hand, one by one, but but there are thousands of photos to extrat from de SDE GDB. I have found a pretty nice script for this task, http://esriaustraliatechblog.wordpress.com/2014/02/25/how-to-export-your-raster-datasets-referenced-... but my problem is that I am working with an old version of arcpy (ArcGIS 10.0 and Python 2.6.5), which does not have the Data Access Module �??da�??, used in this script, i.e. arcpy.da.SearchCursor().
So, since I am not very skilled in Python coding, i need help to modify the script to make it compatible with my older version of arcpy, perhaps using arcpy.SearchCursor() instead of the newly 'da' version of SearchCursor().

I am also interested in bulk import of photos to a raster field, i.e. given a folder with the pictures, load them in the correponding raster field in the feature class.

In summary, I need help with some tips to bulk reading and writing in raster type fields using Python in ArcGIS 10.0.

Thank you in advance.

Regards,
Gaston.
Tags (2)
0 Kudos
2 Replies
XanderBakker
Esri Esteemed Contributor
Hi Gaston,

In theory it is not very difficult to transform the code from an "arcpy.da" search cursor to the "arcpy" cursor. The problem is that the arcpy.SearchCursor does not seem to support raster fields.

The arcpy.da method that works:
import arcpy, os
output_path = r'C:\Forum\Raster attribute\output'

fc = r'C:\Forum\Raster attribute\test.gdb\rasatt01'
fld_raster = 'Raster'
fld_name = 'Name'
flds = (fld_raster, fld_name)

with arcpy.da.SearchCursor(fc, flds) as cursor:
    for row in cursor:
        filename = "{0}.tif".format(row[1])
        row[0].save(os.path.join(output_path, filename))


The arcpy method that doesn't work:
import arcpy, os
output_path = r'C:\Forum\Raster attribute\output'

fc = r'C:\Forum\Raster attribute\test.gdb\rasatt01'
fld_raster = 'Raster'
fld_name = 'Name'

cursor = arcpy.SearchCursor(fc)
for row in cursor:
    filename = "{0}.tif".format(row.getValue(fld_name))
    row.getValue(fld_raster).save(os.path.join(output_path, filename))

del cursor, row


This will throw an error "AttributeError: 'NoneType' object has no attribute 'save'".

You might be interested in a similar thread regarding Blob fields and Raster fields:
http://forums.arcgis.com/threads/108402-How-to-load-image-to-Raster-attribute-field-with-python?p=38...

Kind regards,

Xander
GastonIzaguirre
New Contributor III
Xander,
Thanks for your quick response, it has been very helpful. You're right, I've tried the arcpy method (I could not try arcpy.da because of my version of ArcGIS) and it seems that does not support raster fields.

Apparently the most practical solution is to get an ArcGIS version 10.2...

I'll keep researching and trying to solve this problem with my current version of software. Otherwise I'll have to switch to a new version.

Best regards,

Gaston.
0 Kudos