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?
You can download the data for file based item types. File based items include CSV, Service Definition, Shapefile, File Geodatabase, Powerpoint, etc.
Hosted feature layers and map image layers are not file based items, so you cannot use the item.download() method to download their data.
For hosted feature layers, you can use one of the following ways to get the data:
1) Use extract_data tool from the features.manage_data module (doc: arcgis.features.manage_data module — arcgis 1.0 documentation). It's easy to use, couple examples:
from arcgis.features.manage_data import extract_dataoutputgdb = extract_data([csv_lyr])
csv_lyr = gis.content.get('c8bc7d3c3b60415e9845bc00dcd777ed')outputgdb.download('C:\\xc')
# you can also specify the format:
outputcsv = extract_data([csv_lyr], data_format='CSV')
2) You can get the related data item for the layer, and download the data item used to publish the layer:
relitems = layer_item.related_items("Service2Data")
Hope this helps,
Thank you for the detailed clarification!
I tried the your sample code on a hosted feature layer but got the following error message --
How can I fix it?
I'm not sure why extracting data to a file geodatabase isn't working and the error message isn't very informative.
Please try specifying a different data_format such as Shapefile:
res = extract_data([lyr], data_format='Shapefile')
I can also confirm I'm getting the same problem. Won't export as a file geodatabase, but it will as a shapefile. When i try to specify output as FileGeodatabase, i get "Item does not exist or is inaccessible" which is obviously not the case.
I have a follow-up question. After I downloaded the data using extract_data, I noticed that file item was added to AGOL. Is that the intended result?
agolItem = gis.content.get('xcvxcv345345345')
outputGDB = extract_data([agolItem])
downloadFolderPath = '\\\\your\\path\\Python\\Spatial_Data\\Downloads'
pathWithName = outputGDB.download(downloadFolderPath)