daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. arcpy.DeleteRows_management("Routes_Append")
  2. arcpy.DeleteRows_management("Routes")
  3. incidents.definitionQuery = None
  4. import arcpy
  5. import time
  6. import sys
  7.  
  8. p  = arcpy.mp.ArcGISProject("CURRENT")
  9. m = p.listMaps("Map")[0]
  10.  
  11. #Add the geoprocessing service as a toolbox. Use an alias when importing
  12. arcpy.ImportToolbox(cf_service, "agol")
  13.  
  14. facilities = m.listLayers("Delivery_Sites_No_Admin")[0]
  15. incidents = m.listLayers("VHA_Facilities_No_Other")[0]
  16.  
  17. listx = [2, 3, 4]
  18. obid = "OBJECTID = {}"
  19.  
  20. for oid in listx:
  21.  
  22.     incidents.definitionQuery = obid.format(oid)
  23.     arcpy.SelectLayerByLocation_management(facilities, 'WITHIN_A_DISTANCE', incidents, "150 Miles", 'NEW_SELECTION', 'NOT_INVERT')
  24.     arcpy.CopyFeatures_management(facilities,".../MyProject6.gdb/ObjectID{}".format(oid))
  25.  
  26.     output_routes = ".../MyProject6.gdb/Routes"
  27.     fcs = arcpy.ListFeatureClasses("Object*")
  28.  
  29.     for fc in fcs:
  30.  
  31.         #Call the tool
  32.         result = arcpy.agol.FindClosestFacilities(incidents, ".../MyProject6.gdb/ObjectID{}".format(oid), "Minutes", "", 1)
  33.  
  34.         #Check the status of the result object every 0.5 seconds
  35.         #until it has a value of 4(succeeded) or greater
  36.         while result.status < 4:
  37.             time.sleep(0.5)
  38.  
  39.         #print any warning or error messages returned from the tool
  40.         result_severity = result.maxSeverity
  41.         if result_severity == 2:
  42.             print("An error occured when running the tool")
  43.             print(result.getMessages(2))
  44.             sys.exit(2)
  45.         elif result_severity == 1:
  46.             print("Warnings were returned when running the tool")
  47.             print(result.getMessages(1))
  48.  
  49.         #Get the output routes  and save to a local geodatabase
  50.         result.getOutput(0).save(output_routes)
  51.         arcpy.Append_management("Routes", "Routes_Append", "TEST")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top