I'm still working on this, trying various approaches. First, I can confirm that the function outputs don't show up in the Python results either: result=arcpy.Trace_tn(in_trace_network=tnet, trace_type="UPSTREAM", starting_points='mhsel', barriers=tntb, result_types="SELECTION", selection_type="NEW_SELECTION", functions=[["ADD", "Shape length"]])
print(result) just returns Trace_Results_Aggregated_Points But I'm also having a hard time figuring out how to work with the results of a trace in Python. In the above code, I've specified that the result type should be a SELECTION, but the Results variable shows aggregated points. And if I work with the feature classes that make up the trace network after performing the trace, there doesn't seem to be an active selection. Here's a look at more of the code: # -*- coding: utf-8 -*-
import arcpy
arcpy.env.workspace = "C:\\Path\\clean trace network.gdb"
arcpy.env.overwriteOutput = True
mhfc = "C:\\Path\\clean trace network.gdb\\sewer_trace\\Manholes"
scfc = "C:\\Path\\clean trace network.gdb\\sewer_trace\\ServiceConnections"
gmfc = "C:\\Path\\clean trace network.gdb\\sewer_trace\\GravityMains"
llfc = "C:\\Path\\clean trace network.gdb\\sewer_trace\\Laterals"
mhfields = ['NAME', 'SHAPE@']
tnet = "C:\\Path\\clean trace network.gdb\\sewer_trace\\sewer_tn"
tntb = "C:\\Path\\clean trace network.gdb\\TN_Temp_Barriers"
print('Beginning')
result = arcpy.GetCount_management(mhfc)
print(' Manhole count: ', result[0])
result = arcpy.GetCount_management(scfc)
print(' Service Connection count: ', result[0])
result = arcpy.GetCount_management(gmfc)
print(' Gravity Main count: ', result[0])
result = arcpy.GetCount_management(llfc)
print(' Lateral Line count: ', result[0])
with arcpy.da.SearchCursor(mhfc, mhfields) as cursor:
for row in cursor:
print(row[0])
querystring = "NAME = '"+row[0]+"'"
print(querystring)
arcpy.MakeFeatureLayer_management(mhfc, 'mhsel', querystring)
result = arcpy.GetCount_management('mhsel')
print(' Selected manholes in filter: ', result[0])
result=arcpy.Trace_tn(in_trace_network=tnet, trace_type="UPSTREAM", starting_points='mhsel', barriers=tntb, result_types="SELECTION", selection_type="NEW_SELECTION", functions=[["ADD", "Shape length"]])
print(result)
result = arcpy.GetCount_management(mhfc)
print(' Manhole count: ', result[0])
result = arcpy.GetCount_management(scfc)
print(' Service Connection count: ', result[0])
result = arcpy.GetCount_management(gmfc)
print(' Gravity Main count: ', result[0])
result = arcpy.GetCount_management(llfc)
print(' Lateral Line count: ', result[0]) This gives results like: Beginning
Manhole count: 1853
Service Connection count: 2815
Gravity Main count: 1810
Lateral Line count: 2815
Manhole1
NAME = 'Manhole1'
Selected manholes in filter: 1
Trace_Results_Aggregated_Points
Manhole count: 1853
Service Connection count: 2815
Gravity Main count: 1810
Lateral Line count: 2815
Manhole2
NAME = 'Manhole2'
Selected manholes in filter: 1
Trace_Results_Aggregated_Points
Manhole count: 1853
Service Connection count: 2815
Gravity Main count: 1810
Lateral Line count: 2815
Manhole3
NAME = 'Manhole3'
Selected manholes in filter: 1
Trace_Results_Aggregated_Points
Manhole count: 1853
Service Connection count: 2815
Gravity Main count: 1810
Lateral Line count: 2815 That is, the number of features in the results doesn't change. (I also tried a slightly different approach for the trace, using the SHAPE@ field of the cursor as the starting points, but the results were similar.) Running the trace manually in ArcGIS Pro for Manhol1 shows 29 selected manholes, 22 selected service connections, 29 selected gravity mains, and 22 selected laterals. What am I missing here?
... View more