Select to view content in your preferred language

Input and run python scripts on ArcGIS online to perform network analysis online?

798
2
05-29-2022 06:43 AM
Labels (2)
FraserM
New Contributor III

I only know the basics of ArcGIS Online and have not used it much.

Basically, I have created a python script where when you input a train (in the form of a hyperlink), the script takes the list of stops that train goes through (as listed on the website hyperlink) and uses network analysis to plot the route of that train on a map via these spots. It works in Arc Pro. But I would like to have it on Arc online for easier access.

Is it possible to create a webapp or something that provides an interface with this python script, where you can put in an input into the script and it will run the route analysis and update all the layers etc? 

 

Thanks!

 

Here is the route-creation function to show what needs to be done online - basically, a definition query, followed by updating a table, followed by best route network analysis.

def run_route(stations):
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Proper")[0]
for lyr in m.listLayers("fb_20220514_TIPLOCEastingsandNorthings_SIMPLIFIED_SNAPPED"):
lyr.definitionQuery = "NAME IN " + str(tuple(stations))
arcpy.management.CalculateField("fb_20220514_TIPLOCEastingsandNorthings_SIMPLIFIED_SNAPPED", "Order_Route", "add(!NAME!)", "PYTHON3", """
def add(col):
list_f = {}
for i,v in enumerate(list_f):
if col == v:
return i
""".format(stations), "TEXT", "NO_ENFORCE_DOMAINS")

arcpy.na.AddLocations("Route 4", "Stops", "fb_20220514_TIPLOCEastingsandNorthings_SIMPLIFIED_SNAPPED", "Name Name #;RouteName # #;Sequence # #;TimeWindowStart # #;TimeWindowEnd # #;LocationType # 0;CurbApproach # 0;Attr_Length # 0", "5000 Meters", "Order_Route", "FB_20220529_SplitLine SHAPE;FB_20220529_RailNetwork_13_Junctions NONE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "EXCLUDE", None)
arcpy.na.Solve("Route 4", "SKIP", "TERMINATE", None, '')

0 Kudos
2 Replies
FraserM
New Contributor III

any luck with this ? 🙂

0 Kudos
MikeLachance1
New Contributor III

Are you able to run this in a Notebook in AGOL? Notebook can run Python code in AGOL. I would start there.

0 Kudos