Select to view content in your preferred language

How to query and download multiple feature layers with Notebook at single time?

609
1
11-27-2023 03:01 PM
Adam_Bourque
Regular Contributor

Hello everybody, I have been able to export and save a single feature layer at a time to my local drive, but I am wanting to manipulate the code to allow multiple feature layers to export at once. 

I was hoping it would be as simple as altering the query to use the OR statement or a comma in between feature layer ID, but that has still only allowed me to download one of the feature ID listed. 

I also tried adding num_items = int(50) and max_items=num_items to the script, using this tech support article but had no luck.

 

Really appreciate any help with this

def downloadUserItems(owner, downloadFormat):
try:
# Search items by layers
items = gis.content.search(query='e044b2836f37419f878c9dabc9389bd3', item_type='Feature Service')

# Loop through each item and if equal to Feature service then download it
for item in items:
if item.type == 'Feature Service':
# Retain the feature service title
feature_title = item.title
version = dt.datetime.now().strftime("_%d_%b_%Y")
result = item.export('{}'.format(feature_title) + version, downloadFormat)

# Modify the download path to include the feature service title
download_path = r'C:\Users\GISNOOB\Backups\{}'.format(feature_title)
result.download(download_path)

# Delete the item after it downloads to save space (OPTIONAL)
result.delete()
except Exception as e:
print(e)

 

1 Reply
Adam_Bourque
Regular Contributor

Update: As of now I had a work colleague inform me they use backup features by AGOL folder which is what I changed my code to. I am still curious if there is an easy code manipulation to this code to get multiple layers, if I have a use-case of layers not in one folder. 

0 Kudos