I have found some python that will loop through a list and download all feature layers from ArcGIS online. Found here.
How would I manipulate this script to only search and download a specified feature layer (prompted by input)?
import arcgis from arcgis.gis import GIS gis = GIS(None,'username', 'password', verify_cert=False) # Download all data from a user def downloadUserItems(owner, downloadFormat): try: # Search items by username items = gis.content.search('owner:{0}'.format(owner)) print(items) # Loop through each item and if equal to Feature service then download it for item in items: if item.type == 'Feature Service': result = item.export('sample {}'.format(item.title), downloadFormat) result.download(r'file path of where to store the download') # Delete the item after it downloads to save on space result.delete() except Exception as e: print(e)
Thanks
Solved! Go to Solution.
Apolgies, I'm missing a aclosing apsotrohe. Last line shoudl read:
items = gis.content.search(query=FileName +', type:"Feature Service"')
I'm assuming your putting a toolbox front end on this. So your input parameter would be a string.
So you define that as a variable (assuming it;s first input parameter e.g.:
FileName = arcpy.GetParameterAsText(0)
Then you change the search line to:
items = gis.content.search(query=FileName +', type:"Feature Service")
Apolgies, I'm missing a aclosing apsotrohe. Last line shoudl read:
items = gis.content.search(query=FileName +', type:"Feature Service"')
Much appreciated. Thank you