I use the following code, which copies values from fields on From/To points into From/To fields against each line (different fields if start or end point). This runs on selected lines, but can be easily modified to run on all lines.
import sys, string, os, arcpy, fpformat
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd)
strLineFc = "Line" # Insert name of Line layer
strPointFc = "Point" # Insert name of Point layer
lyrexists = 0
for layer in layers:
if layer.name == strLineFc:
desc = arcpy.Describe(layer.name)
if not desc.FIDSet == '': # Check for selected lines
lyrexists = 1
arcpy.AddMessage("Layer Found")
if lyrexists == 1:
# Line cursor
lineRows = arcpy.UpdateCursor (strLineFc)
lineRow = lineRows.next()
# Edit each Line
while lineRow:
# Get the Line geometry
linePointsArray = lineRow.Shape.getPart(0)
pt_count = linePointsArray.count
pt_begin = linePointsArray.next() # From coordinate
# Check for non two-part lines (multiple vertices)
vertices = 2
while vertices < pt_count:
pt_end = linePointsArray.next()
vertices = vertices + 1
pt_end = linePointsArray.next() # To coordinate
# Print the line object id
arcpy.AddMessage (str(lineRow.ObjectID))
# Point cursor
pointRows = arcpy.SearchCursor (strPointFc)
pointRow = pointRows.next()
# Seach Point database
while pointRow:
# Grab the Point location
point = pointRow.Shape.getPart(0)
# Find the from Point and update the From attributes
if fpformat.fix(point.X,2) == fpformat.fix(pt_begin.X,2) and fpformat.fix(point.Y,2) == fpformat.fix(pt_begin.Y,2):
lineRow.FromID = pointRow.FeatID
arcpy.AddMessage("\t" + pointRow.FeatID)
lineRows.updateRow(lineRow)
# Find the To Point and update the line To attributes
if fpformat.fix(point.X,2) == fpformat.fix(pt_end.X,2) and fpformat.fix(point.Y,2) == fpformat.fix(pt_end.Y,2):
lineRow.ToID = pointRow.FeatID
arcpy.AddMessage("\t" + pointRow.FeatID)
lineRows.updateRow(lineRow)
# Next Point
pointRow = pointRows.next()
# Next Line
lineRow = lineRows.next()
del pointRows
del pointRow
del lineRows
del lineRow