Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arcpy.DeleteRows_management("Routes_Append")
- arcpy.DeleteRows_management("Routes")
- incidents.definitionQuery = None
- import arcpy
- import time
- import sys
- p = arcpy.mp.ArcGISProject("CURRENT")
- m = p.listMaps("Map")[0]
- #Add the geoprocessing service as a toolbox. Use an alias when importing
- arcpy.ImportToolbox(cf_service, "agol")
- facilities = m.listLayers("Delivery_Sites_No_Admin")[0]
- incidents = m.listLayers("VHA_Facilities_No_Other")[0]
- listx = [2, 3, 4]
- obid = "OBJECTID = {}"
- for oid in listx:
- incidents.definitionQuery = obid.format(oid)
- arcpy.SelectLayerByLocation_management(facilities, 'WITHIN_A_DISTANCE', incidents, "150 Miles", 'NEW_SELECTION', 'NOT_INVERT')
- arcpy.CopyFeatures_management(facilities,".../MyProject6.gdb/ObjectID{}".format(oid))
- output_routes = ".../MyProject6.gdb/Routes"
- fcs = arcpy.ListFeatureClasses("Object*")
- for fc in fcs:
- #Call the tool
- result = arcpy.agol.FindClosestFacilities(incidents, ".../MyProject6.gdb/ObjectID{}".format(oid), "Minutes", "", 1)
- #Check the status of the result object every 0.5 seconds
- #until it has a value of 4(succeeded) or greater
- while result.status < 4:
- time.sleep(0.5)
- #print any warning or error messages returned from the tool
- result_severity = result.maxSeverity
- if result_severity == 2:
- print("An error occured when running the tool")
- print(result.getMessages(2))
- sys.exit(2)
- elif result_severity == 1:
- print("Warnings were returned when running the tool")
- print(result.getMessages(1))
- #Get the output routes and save to a local geodatabase
- result.getOutput(0).save(output_routes)
- arcpy.Append_management("Routes", "Routes_Append", "TEST")
Add Comment
Please, Sign In to add comment