Select to view content in your preferred language

Survey123 Tricks of the Trade: Download survey data (with attachments)

22165
54
02-08-2022 03:53 PM
IsmaelChivite
Esri Notable Contributor
13 54 22.2K

 

Do you want to download survey data, including photo attachments? This blog describes, step by step, how you you can do it.

Before we start

 

Before we start, let me point out that there are handy Export tools in the Survey123 website. They let you export your survey data as a CSV, Excel, KML, Shapefile or File Geodatabase. You can choose to export all your survey records, or just a subset.

IsmaelChivite_0-1644364619710.png

You can also export your survey data from the item details page of your survey's layer item.

IsmaelChivite_1-1644364719900.png

The only caveat with these export methods is that you can't download your photo attachments. Technically, you could get your images through the file geodatabase format, but what if you want to export your data and have all your photos in their original format in a folder?   That's what this blog post is about.

 

It is going to take a Python script and ArcGIS Pro

 

Downloading your photos and documents in their original format requires a Python script and ArcGIS Pro. I will describe how to do it step-by-step. Even if you do not have experience with Python, you will be able to do this.

The Python script was developed by @ZacharySutherby  Zach loves Python and he is always looking for new ideas to automate common Survey123 tasks. The script is part of the Survey123 developer documentation.

Download data and attachments

 

IsmaelChivite_0-1644356382310.png

  • Click on the Download button and place the .ipynb file into a well-known location on your computer

IsmaelChivite_1-1644356588848.png

  • Next, open a New project in ArcGIS Pro
  • In ArcGIS Pro, sign in to your ArcGIS Online or ArcGIS Enterprise organization, if not already
  • Open the View ribbon and make sure the Catalog Pane is visible

IsmaelChivite_2-1644356815273.png

  • Open the Analysis ribbon, expand the Python menu and add a new Python Notebook.

IsmaelChivite_3-1644356974266.png

  • From the Catalog pane, right click on the Notebooks category and click on Add Notebook

IsmaelChivite_4-1644357164811.png

  • Use the Add Python Notebook dialog to browse for and select the .ipynb file you downloaded before

IsmaelChivite_5-1644357408312.png

  • Double-click on the export_survey_data_with_attachments.ipynb notebook

IsmaelChivite_6-1644357490443.png

At this point, the notebook will open. With a few minor changes it will be ready to run.

  • Scroll down until you see the second code cell, as shown in the screenshot below

IsmaelChivite_7-1644357712424.png

  • Since you are already signed in, you can ignore the first three parameters (portalURL, username, password)
  • The survey_item_id uniquely identifies the survey for which you want to download data. Here is how you get the survey_item_id value:
    • In a web browser, sign in to survey123.arcgis.com
    • From the survey gallery, click on your survey
    • Get the survey ID as specified below

GetSurveyID.gif

  • Now, take your survey_item_id and replace it in the Python code
  • Change the save_path parameter so it targets an existing directory in your own computer

setSurveyID.gif

Earlier, I asked you to disregard the portalURL, username and password parameters. If you ignored me and set those up, then you can skip the next instruction.  If you left the portalURL, username and password parameters unchanged, then follow the next step

  • In the gis = GIS (portalURL, username, password) line, replace the contents within the brackets with "pro". That is, leave it as: gis = GIS ("pro").  This will essentially reuse the current login information within ArcGIS Pro to run this script and access your survey's data

loginPro.gif

  •  You are now ready to run the script!
  • Open the Cell menu and click Run all

IsmaelChivite_0-1644363172124.png

The script takes about 20 seconds to initialize. Be patient.

  • While the script runs, open the target folder and observe how data is downloaded.
    • You will see a spreadsheet created. It contains the records from your survey.
    • You will then see a second spreadsheet describing what attachments correspond to each record. Note that you could have multiple files (attachments) associated with one record.
    • Finally, a folder will be created for your attachments.The script will download photos, signatures as well as audio files any other type of document attached in this folder.

run.gif

 

The script has a few other parameters that you can tweak. It is all superbly documented so I do not anticipate you will run into any issues with them.

More scripts

 

This is one of many scripts available through the Survey123 developer documentation.  I encourage you to explore and play with other scripts. You will find samples to programmatically create reports, move surveys across organizations and more.

Many thanks to @ZacharySutherby and the Survey123 documentation team for their great work with this. If you have ideas for new scripts, post your comment below.

 

 

 

 

 

 

54 Comments