I have a set of lines that were created as lines between point pairs. Now I need to know, which points the lines connect. I thus want to join the Ids of both points to the line. enter image description here So far I tried to use spatial join, but one ID is always right, while the other ID is always wrong. The lines were created from the points, so they mark the vertices of the lines.
In the end I want to have a single ID, derived from both IDs. For this question I only need to know how to get 2 columns in the line table with the IDs from the vertice points.

How can I (spatial) join two points to one line?

I am using ArcGIS 10.3 on Windows 7.

  • The ID you want to transfer from the Points is ObjectID or Another field holding ID? – BERA May 31 '18 at 8:54
  • It is another field @BERA – blabbath May 31 '18 at 8:59
  • 2
    Why is one always right the other wrong, the two examples you show are correct? 25_28 and 55_53. So what is an example of when it is wrong? – Hornbydd May 31 '18 at 9:59
  • Oh, that is supposed to be an example of how it should be. – blabbath May 31 '18 at 13:57

Use Spatial Join with some Python:

import arcpy
from collections import defaultdict
arcpy.env.overwriteOutput = 1

#Change these lines to match the names of the feature layers and the field names
points = 'Points'
pointidfield = 'PointIDField'
lines = 'Points_PointsToLine'
linefield1 = 'Point1'
linefield2 = 'Point2'

spatjoin = r'in_memory\spatjoin'
arcpy.SpatialJoin_analysis(target_features=lines, join_features=points, 
                          out_feature_class=spatjoin, join_operation='JOIN_ONE_TO_MANY')

d = defaultdict(list)

for key,value in arcpy.da.SearchCursor(spatjoin,['TARGET_FID',pointidfield]):

with arcpy.da.UpdateCursor(lines,['OID@',linefield1,linefield2]) as cursor:
    for row in cursor:
        row[1:] = d[row[0]]

enter image description here

| improve this answer | |

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