Use python to download hosted feature layer as geodatabase?

1365
7
09-08-2020 03:25 PM
KevinBracy_Knight1
New Contributor

Hi there, 

I have been using a script to extract attachments (photos) from a geodatabase and place them into folders named based on a field. However, these data "begin their lives" as attachments on a hosted feature layer on AGOL. Is there a script to automate the conversion of a hosted feature layer to FGDB and download it from AGOL? This would allow me to schedule and automate the entire process (which would be simply smashing!). Can anyone help me out?

Thanks,

Kevin Knight

0 Kudos
7 Replies
Peter_Klingman
Esri Regular Contributor

Hi Kevin, this Esri Support KB article should provide a good start: How To: Back up hosted content by looping through and downloading hosted feature services in FGDB fo... 

Hope this helps,

-Peter

0 Kudos
AFackler_NAPSG
New Contributor III

Hi Peter,

I ran into this article and tried it out on my end, but I am having issues with the layers downloading onto my machine. I got it to at least export the data and commented out the delete line to make sure they export, but I can't figure out what I'm doing wrong to have it download locally.  Do you have any guidance? 

0 Kudos
Peter_Klingman
Esri Regular Contributor

Hi @AFackler_NAPSG -  what is the error message returned? 

I would use a print statement on your path to make sure it's going to an actual location on your machine - additionally, are you running this locally in an ArcGIS Pro Python environment?

Thanks,

-Peter 

0 Kudos
AFackler_NAPSG
New Contributor III

Peter-

I was running it on PyCharm, but after running it on the Acrpy environment in Pro I was able to download the data locally. Thanks!

0 Kudos
Henry_PeleshBW
New Contributor III

Hi Peter, I am running into this same issue. My folder path is correct, but the content does not download to my folder location. I am running this on ArcGIS Notebook within our ArcGIS Online Organization. I am assuming the Notebook can't access or understand my local machine folder path. Any advice to make this work?

Thanks,

Henry

0 Kudos
ChuckWerstak1
New Contributor II

Hi Peter,

I came across this Esri Support KB article and was wondering if there would be a way to modify it to download hosted feature services that are part of an Organization? 

Thoughts?

Thanks,

Chuck

 

0 Kudos
Peter_Klingman
Esri Regular Contributor

Hi @ChuckWerstak1 - absolutely. You will just need to modify the search query to create a list of items in your organization. This will just look like items = gis.content.search(query='') as the search is limited to only your organization by default. This great article by my colleague goes over the different options for searching for content with the API for Python. 

0 Kudos