[GIS] Copy Features giving ERROR 000210: Cannot create output in ArcPy

arcgis-10.2arcpyerror-000210

I have an issue where I'm trying to save separate feature classes for each route in an already solved closest facility problem, and one seemingly arbitrary route won't save. I tried to look at the original feature class that had all the routes, and I couldn't find anything particularly notable about this one route. Furthermore, just to get an idea of whether there was more than one feature that had a problem, I tried a try-except in arcpy, but every feature class after the one seemingly arbitrary broken one saved just fine. Moreover, when I used Model Builder to create the feature classes, everything worked just fine, without any hitches. But I have to use Python, and it's just not working. Can anyone give any pointers?

Here's the code, although I'm not convinced it's even going to be helpful. (Note: Obviously, the code looks kind of rough, because a good bit of it was exported from Model Builder, and I just reworked what wouldn't export. Also, I'm well aware that turning the features into layers, doing a select, and copying the layers back to features is inelegant in comparison to simply doing a select_analysis, but that's just the last version of the code. Neither way worked.):

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("Network")

# Script arguments
Building_network_1_nodes_1_1 = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Building_network_1_nodes_1_1" 

# Local variables:
Test01_ND = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_ND"
Test01 = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01"
Test01__3_ = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01"

# Process: Make Closest Facility Layer
outNALayer = arcpy.MakeClosestFacilityLayer_na(Test01_ND, "Closest_Facility_Model01", "Length", "TRAVEL_TO", "", "2", "", "ALLOW_UTURNS", "", "NO_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "", "NOT_USED")

# Process: Select
arcpy.Select_analysis(Building_network_1_nodes_1_1, r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_FModel", "node_type = 3")

# Process: Add Locations
arcpy.AddLocations_na("Closest_Facility_Model01", "Facilities", r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_FModel", "", "5000 Meters", "", "Building_network_1mz_1_1 SHAPE;Building_network_1_nodes_1_1 SHAPE;Test01_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Building_network_1mz_1_1 #;Building_network_1_nodes_1_1 #;Test01_ND_Junctions #")

# Process: Select (2)
arcpy.Select_analysis(Building_network_1_nodes_1_1, r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_IModel", "node_type = 1")

# Process: Add Locations (2)
arcpy.AddLocations_na("Closest_Facility_Model01", "Incidents", r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_IModel", "", "5000 Meters", "", "Building_network_1mz_1_1 SHAPE;Building_network_1_nodes_1_1 SHAPE;Test01_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Building_network_1mz_1_1 #;Building_network_1_nodes_1_1 #;Test01_ND_Junctions #")

# Process: Solve
Solved = arcpy.na.Solve(outNALayer, "SKIP", "TERMINATE", "")
arcpy.CopyFeatures_management("Routes", r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_Routes")
arcpy.CopyFeatures_management("Facilities", r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_Facil")
arcpy.CopyFeatures_management("Incidents", r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_Incid")

arcpy.env.overwriteOutput = True

# Script arguments
Routes = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_Routes"
Facilities = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_FModel"
Incidents = r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01\\Test01_IModel"

# Local variables:
Test01 = "C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01"
NATest01_071414_gdb = "C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb"
Test01_A = "C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01_A"

u = [row[0] for row in arcpy.da.SearchCursor(Routes, "IncidentID")][-1]

for v in range(1, u + 1):
    arcpy.MakeFeatureLayer_management(Routes, "Route" + str(v))
    arcpy.SelectLayerByAttribute_management("Route" + str(v), "NEW_SELECTION", """ "IncidentID" = """ + str(v))
    arcpy.CopyFeatures_management(Routes, r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01_A\\Route_" + str(v))
    print "Route " + str(v) + " exported."

The whole rest of the script would work until the last part. Here's an abridged version of the print log:

Route 1 exported.
Route 2 exported.
...
...
...
Route 37 exported.
Route 38 exported.

Traceback (most recent call last):
  File "C:/Users/Me/Desktop/TestFolder/Test_01", line 53, in <module>
arcpy.CopyFeatures_management(Routes, r"C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01_A\\Route_" + str(v))
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures
raise e
ExecuteError: ERROR 000210: Cannot create output C:\\Users\\Me\\Desktop\\TestFolder\\TestGeo.gdb\\Test01_A\Route_39
Failed to execute (CopyFeatures).

I'm at a loss. I have no idea why I'd get that error for that particular feature class. It seems so, like I said, arbitrary. Like I said before, too, it works just fine in Model Builder, but I get this hiccup with arcpy. If anyone has ideas, I'd like to hear them. I feel like I've done all the obvious things, so far.

Best Answer

As mentioned in comments, the issue sounds like corrupted input data. Run a RepairGeometry_management prior to your CopyFeatures_management on your inputs. I have read of other problems using CopyFeatures_management. I recommend using FeatureClassToFeatureClass_conversion instead. It is essentially the same geoprocess, and I've never had or read about issues using it.

Related Question