Export attribute table to excel with photo attachments

16079
27
12-02-2014 12:33 PM
NicholasMartin1
New Contributor II

I am using Collector on a project that relies heavily on photo attachments. Viewing the photographs of collected data points in ArcGIS Online is working well, but I also want to share these photo attachments in other formats.

Specifically, I want to export an attribute table to a spreadsheet with photo attachments viewable on the spreadsheet (or create a report from ArcMap with these photo attachments). I also would like to be able to share feature classes in ArcMap that include photograph attachments. However, I haven’t figured out how to achieve either.

When I export ArcGIS Online feature classes to ArcGIS for desktop, the attachments are viewable in the attachment manager for each point. If I try to export the feature class to share with another party, however, the attachments are lost. Similarly, when I export the attribute table to a spreadsheet the photos aren’t viewable.

So I have two questions:

  1. 1) Is it possible to easily share feature classes in ArcGIS that include photo attachments?
  2. 2) Is it possible to include photo attachments when I export an attribute table to a spreadsheet?

Any help or guidance is appreciated. Thank you!

Tags (1)
27 Replies
StephanLe_Roux
New Contributor II

Thanks Zac,

I should have mentioned that I am trying to do this on a computer with no ESRI sodtware installed only python. Jake's looks like it should be able to do it. I am just trying to get that script working.

Regards

0 Kudos
HunterSimpkins
New Contributor

Hi Jake and Stephan,

Thanks for the code snippet, Jake - it works when I have exactly two photos per one pint.  But if I have zero to three or more photos, I get the same error that Stephan gets = "IndexError: list index out of range"...  How can I modify the code to ignore any points that don't have any photos or only have one photo?  I'm aware that I'd need to add a third Image column to hold additional photos, but what else am I missing...  The error  appears at the line " row[1] = path + os.sep + dict[key][1]".  Thanks much!

...

dict = {}

with arcpy.da.SearchCursor(fc, ["GlobalID"]) as cursor:

   for row in cursor:     

      OID = row[0]

      dict.setdefault(OID, [])     

      with arcpy.da.SearchCursor(table, ["ATT_NAME"], "REL_GLOBALID = '" + str(OID) + "'") as cursor2:        

         for row2 in cursor2:

            dict[row[0]].append(row2[0])

del cursor, cursor2

for key in dict:

   with arcpy.da.UpdateCursor(fc, ["Image1", "Image2"], "GlobalID = '" + str(key) + "'") as cursor:

      for row in cursor:

         row[0] = path + os.sep + dict[key][0]

        row[1] = path + os.sep + dict[key][1]

         cursor.updateRow(row)

del cursor

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Try using a try/except statement.  I haven't tested it, but this should bypass the error:

for key in dict:
   with arcpy.da.UpdateCursor(fc, ["Image1", "Image2"], "GlobalID = '" + str(key) + "'") as cursor:
      for row in cursor:
        try:
           row[0] = path + os.sep + dict[key][0]
           row[1] = path + os.sep + dict[key][1]
        except:
           pass
        cursor.updateRow(row)
0 Kudos
HunterSimpkins
New Contributor

Now I'm getting this error:

Traceback (most recent call last):

  File "C:\DATA\Projects\Sign_Inventory\LameDeerRAB\LameDeerTrip2\export_LameDeer2_step2_REV.py", line 44, in <module>

    for row in cursor:

RuntimeError: workspace already in transaction mode

I added in code to start and stop an edit session so I didn't have to delete the relationship, and that has worked in previous settings where I had exactly two photos per one point...

EDIT -  I figured out that this error refers to the way I started my edit operation. I changed the parameters for the "edit.startEditing" command to "(False, False)" and the try/except statement worked!!!  I had previously set them to False, True.  I'm working with a file geodatabase and only one editing operation, so once I changed it, it ran successfully. Thanks very much for your help and your very prompt response!

0 Kudos
JessicaThompson
New Contributor III

This seems painful... as our data gets updated daily and we want to create daily reports about the features collected including pictures...

Any suggestions on how to use this directly from the SDE?

Thanks!

Jessica

0 Kudos
JakeSkinner
Esri Esteemed Contributor

What format (i.e. PDF, Excel) are you exporting your report to?

0 Kudos
JessicaThompson
New Contributor III

Hoping for PDF – struggling with whole Collector --> ArcMap --> PDF workflow

0 Kudos
AlinaTaus
Occasional Contributor

I am also looking into being able to create a .pdf Report that would allow me to embed any attachments (.jpgs) associated with a particular record.

0 Kudos
AlinaTaus
Occasional Contributor

Hi Jake,

Do you know if there is a way to copy/paste a subset of records from a feature class and still be able to bring over the corresponding attachments?

Thank you!

Alina

0 Kudos
AlinaTaus
Occasional Contributor

I figured out how to get the attachments to show up in a report created through ArcGIS:

  • I  used the script in here to export my attachments to a folder.
  • I then used Jake's suggestion to join the attachment table to the feature class except  I ended up reversing the join since I have more than one attachment per asset.
  • I exported this table and did some field calculations to get the full path to where the attachments were stored.
  • Then, I ran the Create Report Wizard. In the Report Designer, under Design Elements I dragged the Picture element to my report.
  • I changed the Image Source to point to the field where my Full Path is stored and ran the report! It worked!

The only thing I still have to figure out is how to get all attachments associated with one record to show up as one report item.

ReportDesign.JPGReport.JPG