Download Item Data

9167
28
12-28-2016 11:57 AM
LesiMai3
Occasional Contributor

Hi,

I was trying to use the item's download method to download the data associated with a map image layer on Portal. But it doesn't seem to be able to download the data and I got b' ' as the output. I also tried the get_data method, which returns an error message saying "the JSON object must be str, not 'bytes'".

I did a similar workflow on a hosted feature layer on ArcGIS Online. And this time, it was able to download the item. But it only returns the data schema in a dictionary. Is there way to download the actual data behind a hosted feature service? Can the download method work with map image layers?

Or did I miss something here?

Thank you!

Tags (2)
0 Kudos
28 Replies
PhilLarkin1
Occasional Contributor III

Ahjung Kim
You might want to consider creating a replica. However, this might be a premium service.


The arcgis package appears to support this functionality: 

arcgis.features.managers module — arcgis 1.0.1 documentation 

AhjungKim4
Occasional Contributor II

That was the answer I got from the Esri Support: create a replica.  Below is the answer I got from the Esri Support.  I tried it and was able to download with attachments. Thank you. Phil. 

In terms of another way to download the data to file geodatabase, without consuming credits, you could create a replica using the Python API and then download. This is the programmatic equivalent of exporting to a file geodatabase from the Item Details page of a service, or creating a replica and manually entering paramters at the REST endpoint.  You may want to test manually from the Item Details page first and ensure that it works there; if it doesn't it won't work programmatically either, and confirms our suspicion that there could be a data-specific problem.
ANSAdviesgroep
New Contributor II

Hi Ahjung Kim‌ and Phil Larkin‌, 

I was trying the same and I got a .zip with a filegdb, which was great!

However, the filename is 32 random characters long. In the above mentioned Python guide I find this code:

replica1 = ports_flc.replicas.create(replica_name = 'arcgis_python_api_2', layers='0', data_format='filegdb', out_path = 'E:\\demo')

replica1

Can I set the filename of the output-file? I was searching in the list of optional attributes in Phil's link, but all I found was this:

create(replica_name, layers, layer_queries=None, geometry_filter=None, replica_sr=None, transport_type='esriTransportTypeUrl', return_attachments=False, return_attachments_databy_url=False, async=False, attachments_sync_direction='none', sync_model='none', data_format='json', replica_options=None, wait=False, out_path=None)

Did I miss this option? 

Thanks in advance!

EDIT: To be clear: I mean the name of the .gdb in the resulting zip.

0 Kudos
AhjungKim4
Occasional Contributor II

I think this is by the API design. When you create a replica, you need replica's ID needs to be unique so the system assigns global ID to each replica. If you leave naming to the humans, it's likely there will be errors and duplicate values will be generated. So the API doesn't want to expose that option.  These are  just my thoughts, you probably want to ask Esri staff  

The replica_name parameter will only define the replica name on the server. 

ANSAdviesgroep
New Contributor II

Would make sense. Still, I think it would be better if the name was for the gdb and you could still use unique-id's for references. Anyhow, I solved it with Python. Thanks for the response

0 Kudos
JeffWard
Occasional Contributor III

I am trying to create a replica using the process in the link below. The reference says the feature layer needs to have the Extract capability. Mine doesn't, is there a setting I need to change on the item details page that will give the feature layer the Extract capability?

In terms of another way to download the data to file geodatabase, without consuming credits, you could create a replica using the Python API and then download. This is the programmatic equivalent of exporting to a file geodatabase from the Item Details page of a service, or creating a replica and manually entering paramters at the REST endpoint.  You may want to test manually from the Item Details page first and ensure that it works there; if it doesn't it won't work programmatically either, and confirms our suspicion that there could be a data-specific problem.

Thanks,

Jeff

Jeff Ward
Summit County, Utah
0 Kudos
AhjungKim4
Occasional Contributor II

From the feature layer's setting's page, check "Allow others to export to different formats." I think this enables extract. 

JeffWard
Occasional Contributor III

That was what I needed. I had actually done that before posting but I was using Jupyter Notebooks to run my script - I needed to run the previous cells to reload the variable I was checking.

Thanks for your help!

Jeff Ward
Summit County, Utah
0 Kudos
asterxiang
New Contributor

I have a hosted feature service in AGOL which contains multiple hosted feature layers and tables. I'd like to programmatically create backup for these data. In AGOL the layer export is configured enabled, so under each feature layer I can manually export each layer (or table) to another folder in AGOL, which is the desired output. For example:

Pavement Ramp Entrance
 Service URL
Pavement Ramp Exit
Service URL
What I like to to do is to do this export programmatic for each layer and table. However, I could not find the same function in Python API. The "export" function I tried gives an error of: 
'FeatureLayer' object has no attribute 'export'
Looks like the "export" function only works on an item, so I tried on the item (the entire feature service), the export result did not produce the expected result. 
Is this export function not available for feature layer? If so, any other way I can create back up of these data? (I have also tried the extract_data mentioned in the first reply, however the data is editable, so not all layers have data currently and the extract_data failed). Thanks!
0 Kudos