Skip to content

Instantly share code, notes, and snippets.

@nommuna2
Last active April 26, 2019 21:01
Show Gist options
  • Save nommuna2/ce5296e30b01caf62f748f79d3df01ba to your computer and use it in GitHub Desktop.
Save nommuna2/ce5296e30b01caf62f748f79d3df01ba to your computer and use it in GitHub Desktop.
(ArcGIS API for Python) Sample of downloading feature services from AGOL
import arcgis
import json
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.type), downloadFormat)
result.download(r'file path of where to store the download')
except Exception as e:
print(e)
# Function takes in two parameters. Username and the type of download format
downloadUserItems('username', downloadFormat='Shapefile')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment