I would like to go through my feature layers in my ArcGIS Online account and download/save the feature layers as shapefiles to my computer. I've tried this tool and also this and others but with no success. Now I'm trying to load the feature layers from the catalog to TOC in ArcMap. It works fine, I can see them in the TOC and I can copy them manually using CopyFeatures tool, or by right-click and then data-export data. Because I have a lot of feature layers, I wrote a script that will iterate over the layers and save them as shp:
import arcpy import os destPath = r"C:\Users\data from AGOL" mxd = arcpy.mapping.MapDocument(r"C:\Users\data from AGOL\Untitled.mxd") df = arcpy.mapping.ListDataFrames(mxd) for lyr in arcpy.mapping.ListLayers(mxd, '', df): if lyr.isFeatureLayer == True: dest1 = os.path.join(destPath, str(lyr.name) + ".shp") arcpy.CopyFeatures_management(lyr,dest1)
This works fine for some feature layers but for others it fails with the error:
Traceback (most recent call last): File "C:/Users/PycharmProjects/untitled1/copyFeatures.py", line 15, in <module> arcpy.CopyFeatures_management(lyr, dest1) File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures raise e arcgisscripting.ExecuteError: ERROR 000210: Cannot create output C:\Users\data from AGOL\AOI_151213.shp Failed to execute (CopyFeatures).
The following image show one of the problematic feature layer (AOI_151213) and one that is OK (AOI_2015):
The only difference I can think of is that the problematic one, contain some txt files, but I can save it manually and it's fine. This error rises only in the iteration process.
Is there a way to modify my code so that: - I will be able to save the problematic feature layer as shp file - OR at least to add a condition that will not terminate the script, but skip this error (and the following errors) - I'm not sure how to embed such a thing.