In AGOL you can export a layer to Shapefile, but I can't do it with the API for Python. I have only achieved it with some layer, passing through CSV, but it gives me many errors (text fields that pass to numeric, or layers that do not find the delimiter).
Can someone help me?
Thank you very much
An arcgis Item has an export method that will save to another format. For example:
from arcgis.gis import GIS
gis = GIS(username='name', password='pass')
item = gis.content.get('ITEM_ID')
item_shp = item.export(title='item_shapefile', export_format='Shapefile')
# item_shp is stored on AGOL, it can be downloaded locally if desired
item_shp.download()
HI J.R. Matchett
Can this item be queried to reduce download sizes , say everything created in the last week for example ?
Paul
Yes, you can query the features you want, access the SpatialDataFrame, and export to a shapefile. For example:
layer = item.layers[0]
features = layer.query('created_date >= CURRENT_TIMESTAMP - 7')
features.sdf.spatial.to_featureclass('./output.shp')
The output shapefile will be saved locally in this case.
nothing like being 6 years late to the conversation, but I just discovered the easiest way to grab data from a REST end-point, with query option, and save as Shapefile
from arcgis.features import FeatureLayer
# query the FeatureLayer to produce a FeatureSet
print('querying the Feature Layer')
fl = FeatureLayer(_itemUrl)
features = fl.query(where='Shape is not NULL', out_sr=26911)
# save to disk
print('saving the Feature Layer to Shapefile')
features.save(save_location=_pathShps, out_name=_friendlyName + '.shp')