Select to view content in your preferred language

Download Item Data

9721
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
AlistairFox
Occasional Contributor

Hi

any idea whey when i use 

from arcgis.features.manage_data import extract_data

I get No module name 'arcgis.features' 

0 Kudos
by Anonymous User
Not applicable

Alistair Fox‌ Can you check if you have upgraded to version 1.0 of the API? The `features` module is new in v1.0 and not found in v0.3 or earlier.

To check, open your terminal (or Python command prompt if you installed using Pro) and type

conda list

and check the version next to `arcgis` package.

0 Kudos
AlistairFox
Occasional Contributor

yes that was it. all sorted now that i am actually on the 1.0 release

apart from the fact the export_data seems to ignore the output_name attribute? anyone got that to work?

outputgdb = extract_data([csv_lyr],output_name="fred")

layer exported is still the default one esri use when you supply nothing

I've tracked through the code and the ExtractData task is definitely getting passed the output name. When i switch to CSV it seems to use the service name (more usable) so I think it seems to be some hard coding inside the extract data task in online that for zipped file gdb outputs it forces to a set name structure. Can anyone confirm?

0 Kudos
AhjungKim4
Occasional Contributor II

rsingh-esristaff‌ I am also getting the "Item does not exist or is inaccessible" error when I try to download as file geodataabse. Is this a bug? 

0 Kudos
AlistairFox
Occasional Contributor

we have been able to download file geodatabase, but some do fail .At the moment we have a support call in with ESRI. we seem to think it is related to our Survey123 created and published feature classes only.

We have also note that extract_data call also consumes credits ,where as manual export data does not. Anyone know if there is an equivalent that does not consume credits 

AhjungKim4
Occasional Contributor II

I checked our AGOL credit after reading this and it did, in fact, use credit!  Glad you mentioned it otherwise I would have continued to test. Thank you! 

0 Kudos
PhilLarkin1
Regular Contributor

Alistair Fox

You could query the service for the JSON. This doesn't consume credits. The method works best if your feature count is below the return limit of the service. 

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
import arcpy
gis = GIS("http://yourROOT.maps.arcgis.com/","User","Pw")
layer = FeatureLayer("https://services1.arcgis.com/oz19jk1209j09j39j/ArcGIS/rest/services/ServiceName/FeatureServer/0",gis)
featureSet = layer.query(where='1=1', out_fields='*')

rawJSON = featureSet.to_json

jsonFile = 'c:\\somelocalpath\example.json'
localFC = 'c:\\somelocalpath\\Example.gdb\\data'
with open(jsonFile, "w") as file:
    file.write(rawJSON)
arcpy.JSONToFeatures_conversion(jsonFile,localFc
0 Kudos
AlistairFox
Occasional Contributor

Hi Phil,

this looks like a really good solution if i can get it to work. 1st issue was it said arcpy didn't contain function 

JSONToFeatures_conversion

I was running 10.3 Pro on the machine so I copied across a 10.4 arcpy module and now it complains i'm not running arcpy in a conda environment. 

Which i am, even when i run from the pro python interactive terminal it still complains about the environment

any ideas?

0 Kudos
PhilLarkin1
Regular Contributor

It sounds as if you have multiple python environments, neither of which have both arcpy and arcgis packages available. 

Here is what I did to run these together:

1)Install Pro 1.4 

2)Added arcgis using Pro's package manager

3)Run script from Pro's python installation. In my case: C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe


Please post a new question if this does not work for you. 

See screenshot of the package manager:

AhjungKim4
Occasional Contributor II

Thank you for posting this. I have written this as a back-up solution, but it is not ideal for feature services that have related records and attachment photos. Also,  it does not preserve the original OID. Exporting feature service to file geodatabase and downloading it is a workflow supported in ArcGIS Online.  But the Python API, which supposed to promote automating ArcGIS tasks did not include this in the API. But the "extract" workflow which is a premium service that cost a credit for 1,000 data points is somehow included in the API. 

What's worse is now that I know this method consumes credit, I selectively chose a feature service that only has two data points.  But it consumed 15.71 credits per day every time I run the script. It does not reflect the credit consumption rate Esri documented. 

I have an Esri Support ticket open for this but have not received a satisfying answer yet.  

0 Kudos