I have a Survey123 Survey that I've been using to collect data with multiple pictures on each datapoint.
Each datapoint has a barcode to correspond with a physical sample taken from each point. I would like to export the photos out of the survey data, which I have done by creating a script in ArcMap, using the code below from this article:
import arcpy
from arcpy import da
import os
inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
for item in cursor:
attachment = item[0]
filename = 'ATT' + str(item[1])
open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
del item
del filename
del attachment
However this does not allow me to rename the file using the barcode that is associated with that datapoint. So when the photos are exported, they are no longer associated with the relevant data.
I would like to tell the SearchCursor function to also take the sample_id
field from the data table and add that to the filename. When I add the sample_id to the array inside the SearchCursor function like this:
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID', 'sample_id']) as cursor
I get the following error: RuntimeError: A column was specified that does not exist.
I would like help in calling the sample_id
field into the function properly so it can be added to the filename variable.
No comments:
Post a Comment