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
Here's an example using the gis module:
How can I export a Feature Layer in AGOL to Shapefile, using API for Python?
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