Select to view content in your preferred language

photo download and offline map

323
5
4 weeks ago
HariharNepal
Emerging Contributor

I have multiple users asking couple of questions @ChrisLeSueur   @IsmaelChivite 

Is there a way to download only the photos from the Survey123 app using the export feature? I currently use a report template that includes the photos, but I would like to know if it’s possible to export just the images.


Can the offline map include the parcel layer for our enforcement inspections?


Thank you. Survey123 came alone far much better product since I have started to use since 2019. Thank you for making this product very user friendly and useful. I have been used this app to perform inspection to collect point, line and polygon features, pictures and other notes. Thank you very much.

0 Kudos
5 Replies
Neal_t_k
MVP Regular Contributor

For you first question: besides manually download each photo, you will need a python script to batch download photots/attachements:  Download Survey123 data (with attachments)

 

0 Kudos
HariharNepal
Emerging Contributor

Thank you @Neal_t_k . This script downloaded all the photoes from all the surveys conducted by all users. How do I download the pictures for a survey only, I have developed this survey to use statewide by multiple users, I need to download the pictures separatly for each survey. Thank you in advance @ZacharySutherby   

0 Kudos
Neal_t_k
MVP Regular Contributor

As you loop through your features, you have to create a separate folder for each feature to hold the attachments for that feature.

With minimal changes to the script in the tutorial, I think some like this should work:

            feature_object_ids = i.query(where="1=1", return_ids_only=True, order_by_fields='objectid ASC')
            for j in range(len(feature_object_ids['objectIds'])):
                current_oid = feature_object_ids['objectIds'][j]
                current_oid_attachments = i.attachments.get_list(oid=current_oid)
				oid_Folder = os.path.join(save_path, current_oid) #Path for new folder based on Oid
				if not os.path.exists(oid_Folder): #Create folder if it doesn't exisit
					os.mkdir(oid_Folder)
            
                if len(current_oid_attachments) > 0:
                    for k in range(len(current_oid_attachments)):
                        attachment_id = current_oid_attachments[k]['id']
                        current_attachment_path = i.attachments.download(oid=current_oid, attachment_id=attachment_id, save_path=oid_Folder) #Dynamically save to appropriate folder.
                        csvwriter.writerow([current_oid, os.path.join('{}_attachments'.format(re.sub(r'[^A-Za-z0-9]+', '', i.properties.name)), os.path.split(current_attachment_path[0])[1])])

 

0 Kudos
ZacharySutherby
Esri Regular Contributor

Hey @HariharNepal

Additional to @Neal_t_k's suggestion, you can change the WHERE clause in 

feature_object_ids = i.query(where="1=1", return_ids_only=True, order_by_fields='objectid ASC')
            for j in range(len(feature_object_ids['objectIds'])):

to be a specific survey. 

 

`where=1=1` will loop through all the records in the feature layer and download attachments for each one. If you only want one specific survey record you could set the where parameter to something like: 

  • where="objectid=1" - this will return just the survey record whose objectid is equal to 1
  • where="field_name = 'some_value'" - this will return zero to multiple surveys who have 'some_value' set in the attribute field called field_name

You can get really intricate with the where expression, for more info see the Query (Feature Service/Layer) REST API doc topic. 

 

Thank you,
Zach
0 Kudos
Neal_t_k
MVP Regular Contributor

In addition to what @ZacharySutherby said.

If you want to custom name the folders/files from fields in the feature service, instead of a range of oids, you can make a list of features, iterate through those capturing values from the fields in the current feature to name your folder and file with:

feature_object_ids = i.query(where="1=1",  order_by_fields='objectid ASC') #Gets feature data in a set
feat_list=feature_object_ids.features  #Create feature list
for j in feat_list:
		field1 = j.get_value('field1')  #Values from fields you want to using in naming convention
		field2 = j.get_value('field12)  #Values from fields you want to using in naming convention

 

0 Kudos