Looking for a way to automatically assign an 8-character Sink ID to every upstream feature in a geometric network. There are over 500 sinks and about 5000 points and lines upstream from those sinks. Would be great to click on any point or line and see what the Sink ID is, or quickly select records based on which sink they are upstream from.

A similar question is here: How to assign attributes from hydrologic sinks to upstream features?

  • Do you have any polygon/polyline data related to your Sink/Facility ID? (E.g., watershed polygons that include the sink and upstream locations, or polyline streams that go through both sinks and junctions). Are your sinks and junctions point data or some other format? – Baltok Oct 25 '12 at 19:26
  • They're part of a combined sanitary/stormwater network. Not really working with watersheds or catchments in this case. The sinks are actually the lowest point at which stormwater features enter a combined system. The combined system itself has been removed temporarily so that it's a little easier to work with. – Rayner Oct 25 '12 at 19:35
  • That's okay, the concept is still the same. For example, do you have pipeline/canal polyline data that goes through both sinks and junctions? What I'm getting at is the eventual ability to link sinks to junctions spatially through another layer, or some common attribute. – Baltok Oct 25 '12 at 19:43
  • No polygons. As far as polyline data, I only have what I've described. Just the stormwater pipes and stormwater structures. There is one pipe segment between structures, so I don't have a long polyline that 'goes through' all the junctions upstream from a sink. I suppose I could merge each group of pipes upstream from each sink and then do a spatial join. Unfortunately, that would involve manually selecting and merging 500 groups of lines. – Rayner Oct 25 '12 at 20:00
  • And I'm assuming your pipeline data doesn't have any attributing related to the Sink ID? If your Sink ID is only found with the sinks data, and you have no other unique ID to connect with the junctions, and no spatial connection with the sinks and junctions, I think you may be stuck with a manual method. Maybe somebody else has a clever workaround. Sorry. – Baltok Oct 25 '12 at 20:13

This is probably 4 years too late, but I wrote a python function to solve exactly this type of problem. The function loops through each 'sink', traces upstream, captures selected features, and writes into a table. The table associates each feature ID with the sink that initiated the trace, so you can join back to your original features. Right now it only captures lines, but can easily be adjusted to handle points too. You'll also have to adjust for your specific field & file names. I can help adjust the function to fit your data if needed.

def TraceCapture(inflags, geoNetwork, barriers, outPath, outName, traceDirection = "TRACE_UPSTREAM"):   
    flaglList = list(arcpy.da.SearchCursor(inflags, ['OBJECTID', 'UNITID']))
    segmentCapture = []
    for flag in flaglList: 
            trace = flag[0]
            outputLayer = "Trace"
            expression = '"OBJECTID" =' + str(trace)
            arcpy.SelectLayerByAttribute_management(inflags, "NEW_SELECTION", expression)
            arcpy.TraceGeometricNetwork_management(geoNetwork, outputLayer, inflags, traceDirection, barriers)
            arcpy.AddMessage("Trace_" + str(trace) + " complete")

            #access trace from "in_memory"
            for lyr in arcpy.mapping.Layer(outputLayer):
                for x in arcpy.mapping.ListLayers(lyr):
                    if x.name == 'SEWER_1':
                        pipesCursor = arcpy.da.SearchCursor(x, 'ASSETID')
                        for i in pipesCursor:
                            segmentCapture.append((flag[1], i[0])) #main event: append tuples relating manhole UnitID to pipe AssetID                   
        except RuntimeError:
            arcpy.AddMessage("Flag " + str(trace) + " was invalid and skipped.")
    arcpy.SelectLayerByAttribute_management(inflags, "CLEAR_SELECTION")

    #write segmentCapture to a GBD table
    outTable = arcpy.CreateTable_management(outPath, outName)
    arcpy.AddField_management(outTable, "outfallID", "TEXT", "", "", 15)
    arcpy.AddField_management(outTable, "pipeID", "TEXT", "", "", 15)

    with arcpy.da.InsertCursor(outTable, ["outfallID", "pipeID"]) as cursor:
        for row in segmentCapture:

    return outTable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.