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?
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
and check the version next to `arcgis` package.
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?
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
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 arcpygis = 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'arcpy.JSONToFeatures_conversion(jsonFile,localFcwith open(jsonFile, "w") as file:
this looks like a really good solution if i can get it to work. 1st issue was it said arcpy didn't contain function
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
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:
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.