4

I have two shapefile layers in ArcGIS for Desktop 10.

I have one line layer and node layer.

My node layer(shp) has a "code_1" field and line layer has a "code_node" field.

The intersection point of the line layer has only one node.

I want get the code from the "code_1" field of the node layer for the line's "code_node" field

For example, for one line, the first node has code_1=1 and the node at the end of line has code_1=2. In this case the code_node attribute in that line must be "12",.

How can I automatically get the code from the nodes for each line?

enter image description here

  • What do you mean by a "node layer"? Are you perhaps using a geometric network or a network dataset or are these simply points located at intersections of lines in another layer? – PolyGeo Feb 2 '14 at 9:22
  • Hi, I've edited and updated the question to clarify what I think you were asking. If my understanding was incorrect, feel free to revert the question back to its original state. – Devdatta Tengshe Feb 3 '14 at 2:52
  • I think that this question could do with a few more clarifications. Firstly, what kind of solution are you looking for? Arcpy or ArcObjects? what have you tried so far? And Secondly, I think the code_node in the line would be ambiguous. Consider the code 1234; You can't say if the two codes are 1 & 234 or 12 & 34 or 123 & 4. It might be better if you keep a symbol for delimiting the two codes, say 12-34 – Devdatta Tengshe Feb 3 '14 at 2:56
  • reply Devdatta Tengshe: I want find one way to do that, It does not matter which way, ArcObject or .... I need just join of 2 code like 1234 – elena Feb 3 '14 at 4:17
  • reply PolyGeo: yes, I have network – elena Feb 3 '14 at 4:18
4

Use Feature Vertices To Points to get the START points from the line shapefile. Do the same for END points. Name the resulted layers "start" and "end". Then use Spatial Join to join these resulted layers to your node layer separately (Target features: "start" and "end" layers, Join feature: your node layer, JOIN_ONE_TO_ONE, Match Option: Intersect). Name the resulting layers "startJoin" and "endJoin". Add a new field "origin" to your line layer (with the same properties as your "code_1" field, I suggest TEXT format). Join your line layer to "startJoin" (match FID to ORIG_FID) and by field calculator copy "code_1" in the "origin" field. Add another field "destination" to your line layer and do the same (you may want to remove the existing join before doing this) for "endJoin" and get the "code_1" into "destination" field. Fianlly, do this field calculation to your "code_node" field: [origin]&[destination]

  • Is there anyway to do this using a spatial join instead of creating new temporary files? – Sarah Feb 28 '14 at 14:42
  • I am not %100 sure on that but I think we need the starting/ending points anyway. – Arash Feb 28 '14 at 17:00
0

I like the approach suggested by @Arash, but this creates 3 additional files, which really adds up if you have a large network and need to check this regularly. Here's my solution using python.

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)

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.