Batch Exporting Images to Attribute Table and Excel Spreadsheets

1222
4
08-12-2021 11:16 AM
Status: Open
AaronHester
New Contributor II

At the company I work for we have been trying for months, working off and on with Esri Support Services, to find a way to add images collected in Field Maps (in a batch process) to exported files (csv, excel spreadsheets, etc.) but have been unsuccessful and have just found out that there is as of yet not a way to accomplish this task.

Our goal is to get the link as stored on ArcGIS servers (from our AGOL company account) to be added to a table to be exported. An example of the images stored in the layer is shown below.

AaronHester_0-1628791707124.png

The links can be opened individually, and then copied to the table one at a time. But for map layers containing tens of thousands of entries it's a near impossibility to add all images to a table one by one. That's why we're trying to find a way of accomplishing this task in a way that allows us to export them all at once (this can be done for the images themselves to a folder, but we need to get the links to the images stored in a server in a spreadsheet along with the other data for that entry to be given to our customers).

Our company gathers data in the field for our customers and gives it to them in the form of maps and tables. Not being able to provide them with tables (csv or excel workbooks) with images included makes the task of their decision making more difficult when they use said tables containing only lat/long and text descriptions.

4 Comments
JakeSkinner

@AaronHester you can try the following tool:

https://community.esri.com/t5/arcgis-online-documents/show-attachments-in-web-map-popup/ta-p/918926

It will create a new field with a URL of the image stored in the attachment table.  The URL will contain a token, but you could use a Field Calc to remove that portion.

DougBrowning

I do this for 123 but it may help you.  What I do is export them using a Python script into a IIS webserver directory.  I rename them as I export them based on a calculated 123 field.  I also create a dir naming structure as I do this.  Then in our database I can easily calc the http path to the photo using base + dir name created above.  This way when anyone exports to anything it exports the http link that works in everything.  I also got fancy and had a simple Python script that creates a simple index.html with a gallery of the photos so the user does not have to click one by one (but they can to full screen).  For another project I even pushed comments from 123 into the EXIF photo info and then pulled that out and showed in in the index.html.

Little extra work but way more slick.  Plus then when I move the data from AGOL to SQL it all still works.  Long term storage inside AGOL or SDE is not great anyway.

Hope that helps.  I thought I posted all this code somewhere but I can't find it.  Let me know if you want it.

DougBrowning_0-1628802120963.png

 

AaronHester

DougBrowning, that's a great idea. Especially in creating the html site to show them all, and any comments, all in one place. Though I'm not sure if we can make use of this method, at least not yet. Our company doesn't currently use any webservers. We have an AGOL account as opposed to Enterprise, so this might limit our options. I love the idea though, it is very slick.

JakeSkinner, I'm not quite sure if this will work for our purposes either, as many of the entries have either multiple or no images associated with them. Not solely a single image per entry. Nevertheless, I'll test it out and see if we can make it work.

Thank you both for the great suggestions. I really appreciate it.

DougBrowning

IIS comes with Windows server so you could turn it on if you have them.  This works with multiple photos just fine.  My forms have 5-10 images per record.  My forms are before the multiple in one question option.  But I like to use one question per photo so that I can calc a name for it.  Makes export easy.

html one is pretty simple.  This one assumes you have the EXIF tool

import os
import exiftool

inDir = r"C:\temp\Dev\ImageComments\Output"

print "Starting"

for dirpath, dirnames, filenames in os.walk(inDir):

    fileList = os.listdir(dirpath)

    # get a list of jpgs in the folder
    jpgList = []
    for file in fileList:
        if file.endswith("JPG") or file.endswith("jpg"):
            jpgList.append(file)

    # only run on dirs with photos
    if len(jpgList) > 0:

        htmlFile = open(dirpath + "\\index.html","w")

        # build the html
        htmlFile.write("<!doctype html>\n")
        htmlFile.write("<html>\n")
        htmlFile.write("<head> <style> img { border: 5px solid #FFFFFF; } </style> </head>\n")
        htmlFile.write('<title>' + inDir.split("\\")[-1] + '</title>')
        htmlFile.write("<body>\n\n")

        for jpg in jpgList:
            htmlFile.write('  <div style="float:left">\n')
            htmlFile.write('    <a href="' + jpg + '"><img src="' + jpg +'" width="450" style="max-width: 100%;">\n')
            htmlFile.write('    <figcaption style="margin-right:2em;">' + jpg + '</figcaption></a>\n')
            with exiftool.ExifTool() as et:
                jpgComment = et.get_tag("XPComment", dirpath + "\\" + jpg)
            #only write if not blank and take out special chars
            if jpgComment != None:
                #jpgComment = ' '.join(i for i in jpgComment if ord(i)<128)
                htmlFile.write('<p style="width: 450px; word-wrap: break-all;">' + jpgComment + '</p>')
            htmlFile.write('  </div>\n')

        htmlFile.write("\n</body>\n")
        htmlFile.write("</html>\n")

        htmlFile.close()


print "Done"