Assigning from node to node in ArcGIS geometric network?

I'm really new to geometric network and geodatabase, I basically finished all the arcgis tutorial. Anyway I cannot figure out how to fill a from_node and to_node fields in a polyline shape with ids of the junctions feature (added during the geometric network creation). Topology of the network is fine...

2 Answers

These information are with geometric network system tables (topology tables). Using ArcObject you can easily query those information (from , to node) an assign them to the edge feature class. But no function exists with arcpy or python to query these information.

Therefore you have to put the geometric network aside and use spatial relationships (intersect) to find the start and end node of a line feature.

As suggested in comments:

How to assign node IDs to links in a network?

Assign point IDs to respective start and end attributes of a polyline

I finally solved this problem in my geometric network with python. Our old method relies on Attribute Assistant being turned on as new pipes and nodes are added, but it doesn't catch changes if pipes are edited or if someone forgot to turn it on. To rerun Attribute Assistant on the entire network is unbearably slow and somewhat unstable. To give a sense of scale, our geometric network contains 400K+ pipes and 500K+ nodes.

The geometric network build forces the X,Y of the nodes and the pipe ends to be coincident. You can access these locations with the shape tokens in arcpy cursors and match them. The shape tokens for lines return an array of the vertices in the order that they were drawn. In my network, the draw order of the pipes is heavily QA'd because we use this to set the flow directions. So, the first vertex is the start of the pipe, and the last vertex is the end of the pipe.

Reference: ASSETID = id of pipe, UNITID = node id at start of pipe, UNITID2 = node id at end of pipe.

``````nodes = "mergeNodes"
pipes = "SEWER_1"

nodeDict = {}
pipeDict = {}

#populate node dictionary with X,Y as the key and node ID as the value
for node in arcpy.da.SearchCursor(nodes, ["UNITID", "SHAPE@XY"]):
nodeDict[(node[1][0], node[1][1])] = node[0]

#populate pipe dictionary with pipe ID as the key and list of X,Y as values
#vertices populated in the order that the line was draw
#so that [0] is the first vertex and [-1] is the final vertex
for pipe in arcpy.da.SearchCursor(pipes, ["ASSETID", "SHAPE@"]):
for arrayOb in pipe[1]:
for point in arrayOb:
if pipe[0] in pipeDict:
pipeDict[pipe[0]].append((point.X, point.Y))
else:
pipeDict[pipe[0]] = [(point.X, point.Y)]

#populate UNITID with the first vertex of the line
#populate UNITID2 with the final vertex of the line
with arcpy.da.UpdateCursor(pipes, ["ASSETID", "UNITID", "UNITID2"]) as cur:
for pipe in cur:
if pipeDict[pipe[0]][0] in nodeDict:
pipe[1] = nodeDict[pipeDict[pipe[0]][0]]
if pipeDict[pipe[0]][-1] in nodeDict:
pipe[2] = nodeDict[pipeDict[pipe[0]][-1]]
cur.updateRow(pipe)
``````