Script to batch process adding raster datasets as attributes in a feature class

560
4
Jump to solution
04-07-2014 07:49 AM
RebeccaCotteleer
New Contributor
Hello, All.

I have a large set of point features (signs locations) that I would like to add images to. I have the sign feature class in a Geodatabase and I know how to add the images manually one at a time. I think the easiest way to handle this would be to create a field that contains the filepaths for the images (so each cell would read "C:/Data/images/IDnumber.jpg", with IDnumber being unique for each feature), but I don't know how to write the code to use the file path to import the images into the raster field in the feature class.  I'm new to python in general, but can work with code if someone give me an idea of how to format it.

Any help would be greatly appreciated! Thanks.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor
The geodatabase offers the "Attachments" management classes to manage images associated to features/feature classes.

http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000014v000000

Also, Xander has a good example in this thread: http://forums.arcgis.com/threads/96729-Generate-Attachment-Match-Table-Python-script-issue?highlight...

View solution in original post

0 Kudos
4 Replies
JamesCrandall
MVP Frequent Contributor
The geodatabase offers the "Attachments" management classes to manage images associated to features/feature classes.

http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000014v000000

Also, Xander has a good example in this thread: http://forums.arcgis.com/threads/96729-Generate-Attachment-Match-Table-Python-script-issue?highlight...
0 Kudos
RebeccaCotteleer
New Contributor
Thanks! This helps a ton!  I tried to following script, and it doesn't generate any errors, but I also don't see any sign of the pictures being associated with the points. When I use the Identify tool there is no image.

###Adding attachments to geodatabase

import csv
import arcpy
import os
import sys

input = r"Y:/Data/practice_shape/Practice.gdb/test"
inputField = "OBJECTID"
matchTable = r"Y:/Data/practice_shape/Practice.gdb/test"
matchField = "OBJECTID"
pathField = "Image" 
picFolder = r"Y:/Data/practice_shape/images"


try:
    # enable GDB attachments
 arcpy.EnableAttachments_management(input)

    # add attachments tool
 arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)

except:
 print arcpy.GetMessages(2)
0 Kudos
JamesCrandall
MVP Frequent Contributor
Thanks! This helps a ton!  I tried to following script, and it doesn't generate any errors, but I also don't see any sign of the pictures being associated with the points. When I use the Identify tool there is no image.


Just to clarify, you do not see a the little attachment paper clip icon in the identify dialog?  To verify you can use the HTML pop up instead of the identify tool as the result will have the image in the dialog popup instead of having to click the attachment.

Also, check the Geodatabase itself for the __ATTACH table and it's associated RelationshipClass. 

One last thing: have you attempted to manually setup Attachments instead of with Python code?
0 Kudos
RebeccaCotteleer
New Contributor
Thanks for the reply.  After looking back to the ESRI page on the process, I realized that my problem was working on a machine with only a Basic License. My oops. Thanks for the help!
0 Kudos