Trace Network Shortest Path by keeping one start point fixed and iterating other start points

517
1
03-24-2022 08:21 AM
RVG296
by
Occasional Contributor

RVG296_0-1648134795158.png

RVG296_1-1648135178357.png

I have a site which is in Red Triangle and a series  of dams (blue ones) which are upstream with respect to the site. I am trying to compute the shortest path or stream distance from the site to each dam in the network. Currently the dams are not on the Hydro Network, but they are in the form of a separate feature class. I see the shortest path in trace networks works only with two starting points. Is there a way I can assign the site and all the dams as the starting points to compute or return the shortest path distance from site to each dam. I was able to compute the shortest path and distance by manually selecting the site and one of the dam as shown above. How can I reproduce this workflow for each dam in this scenario. I see the TN_TEMP_STARTING_POINTS accept only two starting points. But I was wondering if there is way to keep one starting point (red site) fixed and iterate over rest of the all the starting points (blue) in order to compute the distance. In addition, is there a way to store the distance shown in the messages in the form of a table or through Python Scripting?

0 Kudos
1 Reply
TorbjørnDalløkken2
Occasional Contributor

Hi @RVG296 .

I know it's been a long time since you posted this, but I'll give it a go. In one my projects I'm having almost the same situation as you (computing distances from a fixed point on a trace network), but I'm using several "starting points". I'm using python to iterate the points, just as you mentioned. Here are some ideas on how you can acheive your goal using python, if all your point-features are contained within one featureclass. The output is a featureclass for each of the dams, containing the shortest path. Be aware that I haven't actually tested this code, but it might give you some insights.

 

#Get ID for Site
fixed_point = None
sql_clause = "NAME = 'START_SITE'
with arcpy.da.SearchCursor(fc_dams, ["OBJECTID"], sql_clause=sql_clause") as cursor:
   for row in cursor:
      fixed_point = row[0]

#Get geometries from the other points
list_dams = []
sql_clause = "NAME != 'START_SITE'"
with arcpy.da.SearchCursor(fc_dams, ["OBJECTID"], sql_clause=sql_clause) as cursor:
   for row in cursor:
      list_dams.append(row[0]) 

#loop through list of dams
for damid in list_dams:
   fl_dams = "fl_dams"
   point_ids = str(fixed_point) + "," + str(damid)
   where = '"OBJECTID" IN ('+point_ids+')'
   #select the fixed site and the dam
   arcpy.SelectLayerByAttribute_management(in_layer_or_view=fl_dams,
                                            selection_type="NEW_SELECTION",
                                            where_clause=where)
   
   fc_points = "points"
   fl_points2 = "fl_points2"
   fl_shortestpath = "ShortestPath"+damid
   arcpy.CopyFeatures_management(in_features=fl_dams, out_feature_class=fc_points)
   arcpy.MakeFeatureLayer_management(fc_points, fl_points2)

   arcpy.tn.Trace(r"Dam Trace Network", "SHORTEST_PATH", fl_points2, None,
 "NO_DIRECTION", "Shape length", "INCLUDE_BARRIERS", "VALIDATE_CONSISTENCY",
 "DO_NOT_IGNORE_BARRIERS_AT_STARTING_POINTS", "IGNORE_INDETERMINATE_FLOW",
 None, None, "BOTH_JUNCTIONS_AND_EDGES", None, None, "AGGREGATED_GEOMETRY",
 "NEW_SELECTION", "CLEAR_ALL_PREVIOUS_TRACE_RESULTS", "KortesteVei", 
"Trace_Results_Aggregated_Points", fl_shortestpath, None, 
"DO_NOT_USE_TRACE_CONFIGURATION", '', None)
   
        

 

0 Kudos