How can I know at which point each photo belongs in collector after download?

992
6
09-05-2018 12:22 PM
Elizabetvera
New Contributor

I exported from GDB every single photo: ATT1_photo1.jpg... etc to a windown folder. Now I really appreciate knowing how I can know which photo belongs point. For example, me feature class is about tree, point, I took 3 photos for a tree...so I want to know which photo is relative to point

0 Kudos
6 Replies
RandyBurton
MVP Alum

If the photos were saved as an attachment, there should be linking information in the attachment table.  It should contain the point's object an global IDs.  I use a Python script to export photos which grabs the associated IDs and uses it to rename photos so the link is retained in the file name.

0 Kudos
Elizabetvera
New Contributor

In fact, I exported with a script the photos from GDB:
https://support.esri.com/es/technical-article/000011912 

Also, I can see in the attachment table, how a specific "REL_GLOBALID" (which is the point to which the photos are related to) is repeated to the GLOBALID for all 3 photos.

But, my problem is that the script above does not link or keep the GLOBALID of each photo; the result is a ".jpg" file where the name is (for example) "ATT93_Foto1.jpg".

Can you tell me please the script that exports the photos and keeps the "GLOBAL ID" in the name o generates a table where I can see them.

Thanks you so much.

0 Kudos
RandyBurton
MVP Alum

Here's the script that I use.  It does read information from the parent table to get the Object ID along with the attachment's ID to use in renaming the photo.

import arcpy, os

masterFC = r'C:\Path\to\file.gdb\feature'
masterFlds = [ 'GlobalID', 'OBJECTID' ]

relatedTbl = r'C:\Path\to\file.gdb\feature__ATTACH' # two underscores
relatedFlds = ['REL_GLOBALID', 'ATTACHMENTID', 'DATA', 'CONTENT_TYPE']

saveLocation = r'C:\Path\to\save\attachments'

# Use list comprehension to build a dictionary from a da SearchCursor: { 'GlobalID': (OJECTID,), .... }
masterDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(masterFC, masterFlds)}
# print masterDict


with arcpy.da.SearchCursor(relatedTbl, relatedFlds) as cursor:
    for item in cursor:
        # item[3] is Content Type
        if item[3] == 'image/jpeg': # process only images; where clause can also be used to limit results

            # item[0] is related GlobalID; take first item in masterDict tuple with that key
            f1 = masterDict[item[0]][0] # this is the ObjectID of parent record
            f2 = item[1] # this is the Attachment ID
            # make new filename 
            fileName = "ATT_{}_{}.jpg".format(f1, f2)
            # print filename
            # save the image to the desired location
            saveName = os.path.join(saveLocation, fileName)
            f = open(saveName, 'wb').write(item[2].tobytes())

del  cursor
del item

If there is a short text item in the parent feature that would also be good to have (an id code field, or tree species, for example), the code could be easily modified to include that information in the file name.

# change line 4 to add field
masterFlds = [ 'GlobalID', 'OBJECTID', 'TreeSpecies' ] # field names, not alias
# dictionary would be { 'GlobalID': (ObjectID, 'TreeSpecies',), ...etc... }


# lines 23-25
            
            f2 = item[1] # this is the Attachment ID
            f3 = masterDict[item[0]][1] # tree species (if format is appropriate for file name)
            # make new filename 
            fileName = "ATT_{}_{}_{}.jpg".format(f1, f2, f3)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

While this is not a "script tool", it can be made into one.  Hope this helps.

0 Kudos
Elizabetvera
New Contributor

Thanks you so much, I'll try with this script and I'll comment my result. Really appreciate your help.  

0 Kudos
MichaelKelly
Occasional Contributor III

This script also does this, but communicates with the hosted Feature Layer directly. By default the Object ID is output as part of the output, but Global ID's can also be used.

0 Kudos
Elizabetvera
New Contributor

It was exactly that what I need!!. Now I know which photo (s) is relative  to every single element. Thank you so much!

0 Kudos