1

I am working on simulating resource deployments within arcpy network analyst. I have individual incidents stored in a file database (they have to remain single because later on the script must do a check to ensure there is a resource to deploy. My problem is with the iteration. The first closest facility analysis works but then the script fails before completing the next one. It returns

arcgisscripting.ExecuteError: A python error occurred.
Failed to execute (FindClosestFacilities). 

This is my code snippet below

import arcpy
import time
arcpy.env.workspace = r"c:\Simulation\incidents.gdb"
arcpy.env.overwriteOutput = True
start = time.clock()
arcpy.CheckOutExtension("Network")
featureclasses = arcpy.ListFeatureClasses()

print featureclasses

for fc in featureclasses:       
    arcpy.env.workspace = r"c:\Simulation\incidents.gdb"
    arcpy.env.overwriteOutput = True
    inNetworkDataset = r"c:\Simulation\tempFGDB.gdb\deccan_street\deccan_street_ND"
    inIncidents = fc
    inFacilities = r"c:|Simulation\proposed_csl.shp"
    outGeodatabase = r"c:\Simulation\NA_outputs.gdb"
    outRoutes = "Routes"
    outDirections ="Directions"
    outClosestFacilities = "ClosestFacilities"
    measurement_units = "Minutes"
    with arcpy.da.SearchCursor(fc,("DATE_TIME", "OBJECTID")) as cursor:
        for row in cursor:
            vALUE = str(row[1])

    # Run FindClosestFacilities. Choose to find only the closest facility.
    arcpy.na.FindClosestFacilities(fc, inFacilities, measurement_units, inNetworkDataset, outGeodatabase, outRoutes + "_" + vALUE, outDirections + "_" + vALUE, outClosestFacilities + "_" + vALUE, Number_of_Facilities_to_Find=1)

print "Script completed successfully"

elapsed = (time.clock() - start)
print("Execution time: " + str(elapsed))

closed as unclear what you're asking by PolyGeo Jan 11 '17 at 7:44

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What purpose does the search cursor solve? VALUE never changes since you are always getting the last OID each iteration of the outer for loop. – Paul Nov 29 '16 at 17:46
  • To identify outputs, I don't know how to call specific field values from the feature class list directly and pass it to append to output names – Bornterra Nov 29 '16 at 18:50
  • 2
    When you define InFacilities it is using the wrong slash in path. – Hornbydd Nov 30 '16 at 8:58
  • 1
    Yep, InFacilites. Also, consider using an error handler in your scripts. If the script fails the error handler will return more detailed information about why it failed- both from the arcpy side of things and the Python/syntax side . desktop.arcgis.com/en/arcmap/10.3/analyze/python/… – GBG Nov 30 '16 at 16:25
  • The InFacilities slash changed somehow when I copied and pasted my code. However even with that fixed and the error handler I get the same generic errors. – Bornterra Nov 30 '16 at 18:45