ODCM_Table = arcpy.na.Solve(outNALayer) #Solves the Origin-Destination Cost Matrix and produces the ODCM_Table arcpy.TableToTable_conversion(ODCM_Table, workspace + "\Default.gdb", "ODCM") # Thought this should convert result to GDB Table
print ODCM_Table GPL0
Solved! Go to Solution.
arcpy.da.FeatureClassToNumPyArray(ODCM_LYR, "*")
I think I've angered the GIS gods...
arcpy.da.FeatureClassToNumPyArray(ODCM_LYR, "*")
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
RuntimeError: cannot open 'C:\ArcGIS\SYSTEM\COF\Data\BG2Branches.lyr'
Is there a BG2Branches Feature Class (not a .lyr)?
I don't see where you are assigning ODCM_LYR to anything, is that just missing from the posted code.
ODCM_LYR = arcpy.na.Solve(outNALayer) ODCM_LYR = ODCM_LYR.getOutput(0)
also, if you are trying to convert from the numpyarray to FC, wouldn't that be NumPyArrayToFeatureClass instead of FeatureClassToNumPyArray ?
arcpy.TableToTable_conversion("BG2Branches\Lines", workspace, str(cbsaFD) + "_ODCM")
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: "BG2Branches\Lines" arcpy.TableToTable_conversion("BG2Branches/Lines","C:/Users/jdk588/Documents/ArcGIS/Default.gdb","ODCM_Test","#","""Name "Name" true true true 128 Text 0 0 ,First,#,/ODLines,Name,-1,-1;OriginID "OriginID" true true true 4 Long 0 0 ,First,#,/ODLines,OriginID,-1,-1;DestinationID "DestinationID" true true true 4 Long 0 0 ,First,#,/ODLines,DestinationID,-1,-1;DestinationRank "DestinationRank" true true true 4 Long 0 0 ,First,#,/ODLines,DestinationRank,-1,-1;Total_Length "Total_Length" true true true 8 Double 0 0 ,First,#,/ODLines,Total_Length,-1,-1""","#")
arcpy.na.Solve(outNALayer) arcpy.SaveToLayerFile_management(outNALayer, workspace + "\\" + outLayerFile, "RELATIVE") mxd = arcpy.mapping.MapDocument(r" C:\Program Files (x86)\ArcGIS\Desktop10.1\MapTemplates\Traditional Layouts\LetterPortrait.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] addlyr = arcpy.mapping.Layer(r???C:\Temp\BG2Branches.lyr") arcpy.mapping.AddLayer(df, addlyr) for lyr in df: if lyr.name == "Lines": arcpy.TableToTable_conversion(lyr, addlyr, "ODCM_Table") arcpy.mapping.RemoveLayer(df, lyr) arcpy.Delete_management(workspace + ???\\??? + str(addlyr) + ???.lyr???) else: arcpy.AddError (???ODCM Lines Not Found.???)
outfile = workspace + "\\" + outLayerFile newtable = workspace + "\\" + "ODCM_Table" arcpy.na.Solve(outNALayer) arcpy.SaveToLayerFile_management(outNALayer, outfile , "RELATIVE") arcpy.TableToTable_conversion(outfile ,newtable,"#","#","#")
class LicenseError(Exception): pass import arcpy, os, traceback, sys, tkMessageBox from arcpy import env arcpy.env.overwriteOutput = True #Checkout Network Analyst License try: if arcpy.CheckExtension("Network") == "Available": arcpy.CheckOutExtension("Network") else: # Raise a custom exception # raise LicenseError #Set Variables Members = r"C:\ArcGIS\HSD\HSD_May2013\HSD.gdb\Members" Shell_D = r"C:\ArcGIS\HSD\HSD_May2013\HSD.gdb\Shell_D" Distance = r"C:\ArcGIS\HSD\HSD_May2013\HSD.gdb\Distance" ND = r"C:\ArcGIS\Geodabases\Basemap.gdb\na\na_ND" OD_Lines = r"in_memory\OD_Lines" Lines = r"OD_Matrix\Lines" OD_Matrix = "OD_Matrix" #Processes for Distance Analysis arcpy.MakeODCostMatrixLayer_na(ND,OD_Matrix,"Distance","","1") arcpy.AddLocations_na(OD_Matrix, "Origins", Members, "", "", "", "", "", "Clear") env.workspace = r"C:\ArcGIS\HSD\HSD_May2013\Database" workspaces = arcpy.ListWorkspaces("Distance*", "FileGDB") for workspace in workspaces: expression1 = workspace[-6:-4] print "Distance: " + expression1 + " Miles" env.workspace = workspace fclist = arcpy.ListFeatureClasses() for fc in fclist: expression2 = '"' + str(fc[4:8]) + '"' arcpy.CalculateField_management(Shell_D, "SpecialtyCode", expression2, "PYTHON_9.3") print "Calculating Distance for Specialty Code " + expression2 arcpy.AddLocations_na(OD_Matrix, "Destinations", fc, "Name Code #", "", "", "", "", "Clear") arcpy.Solve_na(OD_Matrix, "SKIP","CONTINUE") arcpy.Select_analysis(Lines, OD_Lines, "\"Total_Distance\" <=" + expression1) count = arcpy.GetCount_management(OD_Lines) arcpy.CalculateField_management(Shell_D, "Distance", count, "PYTHON_9.3") arcpy.Append_management (Shell_D, Distance) except: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) tkMessageBox.showwarning("Error",pymsg) finally: # Check in the Network Analyst extension arcpy.CheckInExtension("Network")