Using Python I am would like to take files from agol and download them onto my laptop as shapefile. Does anyone have code that they could share with me? I am new to python
Hi, I posted an error when I tried the code sample from How To: Download feature service items from ArcGIS Online using ArcGIS API for Python (esri.com):
# define the download format and the specified output path # path = my_test_path ## changed for forum post def downloadUserItems(owner, downloadFormat): try: # Search items by username # items = gis.content.search('owner:{0}'.format(owner)) # print(items) # search items by group group = gis.groups.search("title:ArcGIS API Test", max_groups=15)[0] items = group.content() print(items) # Loop through each item and if equal to Feature service then download it for item in items: print(item.type) # if item.type in ['Feature Service', 'Vector Tile Service', 'Scene Service']: result = item.export('sample {}'.format(item.title), downloadFormat, wait =True) result.download(path) # Delete the item after it downloads to save space (OPTIONAL) # result.delete() print("Exported item: {}".format(result)) except Exception as e: print(e) # Function takes in two parameters. Username and the type of download format downloadUserItems('dsfgis', downloadFormat='Shapefile')
And I get this error:
[<Item title:"Storm_Feature" type:Feature Layer Collection owner:dsfgis>] Feature Service Could not export item.
Your help/insights would be appreciated!
Hi,
There is a useful code sample in the following link showing how to download all items owned by a particular user - How To: Download feature service items from ArcGIS Online using ArcGIS API for Python (esri.com):
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) # Function takes in two parameters. Username and the type of download format downloadUserItems('username', downloadFormat='Shapefile')
Alternatively, if you have access to arcpy you could use the Feature Class to Feature Class tool - Feature Class To Feature Class (Conversion)—ArcGIS Pro | Documentation
Finally, the following post may also be of use - Solved: Re: Downloading AGOL feature as Excel file and sha... - Esri Community
Best,
Hamish
Here's an example using the gis module:
How can I export a Feature Layer in AGOL to Shapefile, using API for Python?
https://community.esri.com/t5/arcgis-api-for-python-questions/how-can-i-export-a-feature-layer-in-agol-to/td-p/781687
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.